私はxmlファイルがあり、私は自分のコードでプログラム的にRelativeLayoutの部分を繰り返したい。実行時にどのようにレイアウトを繰り返すことができますか。
<?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" >
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.11" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="39dp"
android:layout_marginTop="26dp"
android:text="Button" />
</RelativeLayout>
</LinearLayout>
回答:
回答№1は0ここに 実行時にレイアウトリストを作成して作成することについての私の答えを見つけることができます。
回答№2については2
LayoutInflater vi = (LayoutInflater) currentContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.id, null);
parentview.add(v);
回答№3の場合は1
あなたは使うことができます LayoutInflater XMLレイアウトを複数回インスタンス化する。
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = (View) inflater.inflate(R.layout.yourxml, null);