DataTableというTableLayoutをプログラムで作成しました(プログラムでTableLayoutを作成するのと同様です)。次に、プログラムでテーブルをRelativeLayoutに追加する必要があります。私は次のことを試みます:
DataTable dataTable = new DataTable(getApplicationContext(), data);
RelativeLayout rootLayout = (RelativeLayout) findViewById(R.id.rel_view);
rootLayout.addView(dataTable);
dataTableが表示されますが、配置が混乱しています。私の問題は、dataTableに関連して他のコンポーネントを設定することです。
以下に、私が最終的に何をしたいのかを示します。ただし、my_table
dataTableが移動する場所です。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rel_view"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MyViewActivity" >
<TableLayout
android:id="@+id/my_table"
android:layout_alignParentTop="true" />
<Spinner
android:id="@+id/my_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/my_table" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/my_table"
android:layout_toRightOf="@id/my_spinner"
android:text="@string/button_mine"
android:onClick="buttonPushed" />
</RelativeLayout>
1つの考えは、基本的にxmlレイアウトを私が持っている方法で維持し、次に何らかの方法my_table
でdataTableに置き換えてid
、フィールドとlayout_alignParentTop
フィールドを維持することです。でもどうやってやるのかわからない。
別の考えは使用することです
RelativeLayout.LayoutParams layout = new RelativeLayout.LayoutParams(LayoutParams.blahblah)
しかし、配置を設定する方法がわかりません。また、繰り返しid
ますが、他のビューに関連するものはありません。
上記が明確でない場合、私の主な質問はこれです:RelativeLayoutで、プログラムで追加された要素(TableLayout)に対してxmlハードコードされた要素(ButtonおよびSpinner)をどのように整列させますか?