0

私はにlayout.xmlパネルを持っていますandroid(R.layout.items)

<?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" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="textview1: " />

    <LinearLayout
        android:id="@+id/Panel1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="6dp"
        android:orientation="horizontal"
        android:padding="1dp" >

    <EditText
        android:id="@+id/agente2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.1"
        android:maxLength="5"
        android:singleLine="true" />

    <EditText
        android:id="@+id/agente2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.3"
        android:enabled="false"
        android:singleLine="true" >
    </EditText>
    <LinearLayout
        android:id="@+id/Panel2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="6dp"
        android:orientation="horizontal"
        android:padding="1dp" >
    <CheckBox
        android:id="@+id/cbTipoIncidente1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CheckBox" />
.....

このパネルにはlinearlayout、動的かつプログラム的に別のパネルに追加したいものがいくつかありlayout(r.layout.other)ます。

r.layoutinflateを使用すると、リソースを追加することしかできず、追加することはできませんr.id。に単一のビュー(たとえば、panel1)を追加したいと思いr.layout.otherます。何か案は?

4

2 に答える 2

3

LinearLayoutそれを個別に保存し、次のようにタグを使用して別のファイルをpanel.xml呼び出します。layout.xml<include>

   <LinearLayout ... >
         <include layout="@layout/panel" />
  </LinearLayout>
于 2013-02-25T09:17:38.093 に答える
2

この概念を使用する

LinearLayout global_panel = new LinearLayout (this);
        global_panel.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        global_panel.setGravity(Gravity.FILL);
        global_panel.setBackgroundResource(R.drawable.back);
于 2013-02-25T09:16:46.147 に答える