0

私は Android のテーブル レイアウトで遊んでいて、同じセル内に 2 つのテキストビューをプログラムで配置しようとしています。この件について調査したところ、同じセルに複数の要素を追加するにはレイアウトを使用する必要があることがわかりました。

RelatvieLayout を使用してこれを実行しましたが、何らかの理由でテキストビューの一部が失われました。なぜ誰か知っていますか??

私のコードは次のとおりです。

RelativeLayout relativeLayout = new RelativeLayout(this);
RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);

RelativeLayout.LayoutParams layout1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layout1.setMargins(0, 0, 0, 0); //(left, top, right, bottom)
layout1.addRule(RelativeLayout.CENTER_IN_PARENT);

RelativeLayout.LayoutParams layout2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layout2.setMargins(50, 50, 0, 0); //(left, top, right, bottom)
layout2.addRule(RelativeLayout.CENTER_IN_PARENT);

t1.setLayoutParams(layout1);
t2.setLayoutParams(layout2);

relativeLayout.addView(t1);
relativeLayout.addView(t2);

row.addView(relativeLayout);

tableView.addView(row, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 

私のレイアウトコードは次のとおりです。

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TableLayout
            android:id="@+id/ourTable"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="7.64" >

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >
            </TableRow>

            <TableRow
                android:id="@+id/tableRow2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >
            </TableRow>

            <TableRow
                android:id="@+id/tableRow3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >
            </TableRow>

            <TableRow
                android:id="@+id/tableRow4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >
            </TableRow>
        </TableLayout>
    </LinearLayout>

</ScrollView>
4

0 に答える 0