1

2つのテキストと1つの画像のセットで構成されたレイアウトAがあり、その後に2つのテキストと1つの画像のセットが続きます(これらは線で区切られています)。このレイアウト(Aとしましょう)を膨らませて、別のレイアウト(Bとしましょう)の中に入れたいと思います。問題は、画像とセパレータがBの真ん中にあるのに、Aの真ん中にあることです。私のコードは次のとおりです。

レイアウトA(膨らませる):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rootLayout"
    android:layout_width="fill_parent"
    android:layout_height="55dp"
    android:background="@drawable/bg_numeros"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/separator"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/divisoria_numeros" />

    <ImageView
        android:id="@+id/artistsDoll"
        android:layout_width="60dp"
        android:layout_height="fill_parent"
        android:layout_centerVertical="true"
        android:layout_toLeftOf="@+id/separator"
        android:scaleType="fitCenter"
        android:src="@drawable/boneco_artistas_numeros" />

    <ImageView
        android:id="@+id/songsDoll"
        android:layout_width="60dp"
        android:layout_height="fill_parent"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:scaleType="fitCenter"
        android:src="@drawable/bonecos_numeros" />

    <TextView
        android:id="@+id/songsNumbers"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/artistsDoll"
        android:layout_toLeftOf="@+id/songsDoll"
        android:layout_toRightOf="@+id/separator"
        android:text="blabla"
        android:textColor="#333333"
        android:textSize="14dp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/songsText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/songsNumbers"
        android:layout_toLeftOf="@+id/songsDoll"
        android:layout_toRightOf="@+id/separator"
        android:text="SOME SONGS"
        android:textColor="#999999"
        android:textSize="11dp" />

    <TextView
        android:id="@+id/artistsNumbers"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignTop="@+id/artistsDoll"
        android:layout_toLeftOf="@+id/artistsDoll"
        android:text="blabla"
        android:textColor="#333333"
        android:textSize="14dp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/artistsText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/artistsNumbers"
        android:layout_toLeftOf="@+id/artistsDoll"
        android:text="SOME ARTISTS"
        android:textColor="#999999"
        android:textSize="11dp" />

</RelativeLayout>

私はこのように膨らんだレイアウトを挿入しています:

RelativeLayout A = (RelativeLayout) Patterns.mainContext
                      .getLayoutInflater()
                      .inflate(R.layout.A, null);

RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
rlp.addRule(RelativeLayout.BELOW, someTopLayout.getId());
B.addView(A, rlp);

属性android:layout_height="fill_parent"android:layout_centerHorizontal="true"は画像に設定されていますが、BではなくAの中央に配置されることを期待していることに注意してください。

何か助けは?

4

1 に答える 1

1

ここにある解決策:layoutinflatorを使用して実行時にビューを追加する方法は? 私の問題を解決しました。

RelativeLayout A = (RelativeLayout) Patterns.mainContext
                  .getLayoutInflater()
                  .inflate(R.layout.A, parentLayout, false);
于 2012-01-13T15:34:14.703 に答える