アプリケーションの場合、いくつかのオブジェクトを必要な正確な位置に配置する必要があるため、今回は AbsoluteLayout を使用する必要があります。
次の XML とまったく同じようにボタンを動的に追加したいのですが、実行時に追加します。
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/backbutton"
android:text="TEST123"
android:layout_x="120px"
android:layout_y="120px"
android:layout_width="100px"
android:layout_height="100px" />
</AbsoluteLayout>
これをアーカイブするにはどうすればよいですか? 以下のコードでボタンを追加してみましたが、layout_xとlayout_yを設定する関数が今のところ見つかりません。これどうやってするの?ありがとう。
AbsoluteLayout al = new AbsoluteLayout(this);
Button t = new Button(this);
t.setHeight(300);
t.setWidth(300);
t.setText("TEST123");
// x y ???
setContentView(al);