0

ビュー (テーブルとヘッダーテーブル) が重複しているアクティビティがあります

private ViewGroup createTable(ViewGroup root) {
    // TODO Auto-generated method stub
    TableLayout table = new TableLayout(getActivity());
    table.setStretchAllColumns(true);
    table.setShrinkAllColumns(true);

    TableLayout headertable = new TableLayout(getActivity());
    headertable.setStretchAllColumns(true);
    headertable.setShrinkAllColumns(true);

    /* Adding stuff to headertable which contains...  */
            /* ...table content I DO NOT WANT to scroll*/

    root.addView(headertable);

    for (int i = -2; i <= 100; i++) {

                    if (i > 0) {
            /*Set up empty views*/
                /*...3 empty views will be set*/
                    }

        /* Adding stuff to table which contains...  */
                    /* ...table content I WANT to scroll*/

    }

    ScrollView sv = new ScrollView(getActivity());
    sv.addView(table);
    root.addView(sv);
    return root;
}

基本的に、テーブルをヘッダーテーブルとテーブルに分割しました。テーブルをスクロールしたいが、ヘッダーテーブルはスクロールしたくない。ただし、私のテーブル (headertable の下にある必要があります) が重なっています。したがって、上記でわかるように、空のビューを追加しました (そのため、headertable (3 つの行がある) の下から開始します) が、これは機能しないことに気付きました。下にスクロールするとすぐに、空のビューが上にスライドし、ヘッダーテーブルが再び遮られます。

私の意見はすべてプログラムで作成されました。このアクティビティはフラグメント アクティビティです。XML ファイルには次のものが含まれます。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff" >

</FrameLayout>

どんな助けでも大歓迎です。前もって感謝します。

4

1 に答える 1

0

それが最善の方法かどうかはわかりませんが、次のようにします。

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
<FrameLayout
    android:id="@+id/pane"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
</LinearLayout>

header_list.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <TextView
            android:id="@+id/header"
            android:layout_width="fill_parent"
            android:layout_height="30dp"
            android:layout_alignParentTop="true" />
    <ListView
            android:id="@id/android:list"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_below="@id/header" />
    <TextView
            android:id="@android:id/empty"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/header"
            android:gravity="center" />
</RelativeLayout>

RecipeListFragment.java

public class RecipeListFragment extends ListFragment {
    private TextView header;
    private TextView empty;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.common_list, container, false);
        header = (TextView) v.findViewById(R.id.header);
        empty = (TextView) v.findViewById(android.R.id.empty);
        header.setText(R.string.header_recipe);
        empty.setText(R.string.empty_recipes);
        return v;
    }
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        // List code here
    }
}

このコードにはヘッダー行が 1 行しかありませんが、その TextView を TableLayout に変更し、同じ方法で入力して、ヘッダー テーブルを指定し、その下にリストを配置して、その上にスクロールしないようにすることができます。

お役に立てれば!

于 2012-04-14T14:03:25.280 に答える