3

レイアウトにこれらの糸くずの警告があります

Nested weights are bad for performance (11 items)
data.xml has more than 80 views, bad for performance

これは私のレイアウトです:

ここに画像の説明を入力

私のレイアウトはデータを表示することです。このデータはほとんど表として示されていますが、いくつかの「行」は 3 または 4でなければならず、他のものは 6 または 7 です。これらのいくつかにはまったく同じ幅を持たTextViewsせたいので、それらすべてを作成して使用し、何を達成するために使用します。私が欲しい。TextViewsLinearLayoutandroid:weightSumandroid:layout_weight

一部のビュー (データを表示するために必要なビュー) を削除できないため、レイアウトのパフォーマンスを向上させるにはどうすればよいですか?

私は使用しようとしましたが、それでは使用RelativeLayoutできませんandroid:weightSumand android:layout_weight.

ありがとう。

ファヴォラス

編集

ごめん。XML がそれほど重要であることを理解していませんでした。

ここに巨大なコードがあります:

http://pastebin.com/0mehGx2z

さらにいくつかの説明。

ほぼ 50 列のテーブルが 1 つあるデータベースがあります。

データベースに対してクエリを実行すると、このクエリは Cursor を返します。結果は に表示されますListView。ユーザーがこれらの結果の 1 つを選択すると、このレイアウトに「送信」され、これらのフィールドすべてにデータが表示されます。

4

1 に答える 1

2

あなたは本質的にListViewがすでに行っていることを再現しようとしているように私には見えます。このタスク用に設計および最適化されているため、ListViewまたはGridViewを使用することをお勧めします。カスタムアダプタを使用すると、カスタムレイアウトを表示できます。さらに。私は、RelativeLayoutがLinearLayoutよりも高速であることを読んだことを覚えていると思います。子ビューの配置を決定するのにそれほど苦労する必要がないためと思われます。考慮すべき他の何か。

Googleのは、ローダーを使用してListViewを動的にロードする方法を示しています。すでにデータがある場合は、ローダー機能を簡単に取り除くことができます。

public class ListViewLoader extends ListActivity
        implements LoaderManager.LoaderCallbacks<Cursor> {

    // This is the Adapter being used to display the list's data
    SimpleCursorAdapter mAdapter;

    // These are the Contacts rows that we will retrieve
    static final String[] PROJECTION = new String[] {ContactsContract.Data._ID,
            ContactsContract.Data.DISPLAY_NAME};

    // This is the select criteria
    static final String SELECTION = "((" + 
            ContactsContract.Data.DISPLAY_NAME + " NOTNULL) AND (" +
            ContactsContract.Data.DISPLAY_NAME + " != '' ))";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Create a progress bar to display while the list loads
        ProgressBar progressBar = new ProgressBar(this);
        progressBar.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT, Gravity.CENTER));
        progressBar.setIndeterminate(true);
        getListView().setEmptyView(progressBar);

        // Must add the progress bar to the root of the layout
        ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
        root.addView(progressBar);

        // For the cursor adapter, specify which columns go into which views
        String[] fromColumns = {ContactsContract.Data.DISPLAY_NAME};
        int[] toViews = {android.R.id.text1}; // The TextView in simple_list_item_1

        // Create an empty adapter we will use to display the loaded data.
        // We pass null for the cursor, then update it in onLoadFinished()
        mAdapter = new SimpleCursorAdapter(this, 
                android.R.layout.simple_list_item_1, null,
                fromColumns, toViews, 0);
        setListAdapter(mAdapter);

        // Prepare the loader.  Either re-connect with an existing one,
        // or start a new one.
        getLoaderManager().initLoader(0, null, this);
    }

    // Called when a new Loader needs to be created
    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
        // Now create and return a CursorLoader that will take care of
        // creating a Cursor for the data being displayed.
        return new CursorLoader(this, ContactsContract.Data.CONTENT_URI,
                PROJECTION, SELECTION, null, null);
    }

    // Called when a previously created loader has finished loading
    public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
        // Swap the new cursor in.  (The framework will take care of closing the
        // old cursor once we return.)
        mAdapter.swapCursor(data);
    }

    // Called when a previously created loader is reset, making the data unavailable
    public void onLoaderReset(Loader<Cursor> loader) {
        // This is called when the last Cursor provided to onLoadFinished()
        // above is about to be closed.  We need to make sure we are no
        // longer using it.
        mAdapter.swapCursor(null);
    }

    @Override 
    public void onListItemClick(ListView l, View v, int position, long id) {
        // Do something when a list item is clicked
    }
}
于 2012-08-10T16:35:13.303 に答える