12

私は次のレイアウトを持っています。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            style="@style/list_item_bottom">

    <TextView android:id="@+id/list_item_name"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"/>

    <ViewStub android:id="@+id/stub_for_alt_name"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_below="@+id/list_item_name"
              android:layout="@layout/text_view_alt_name"/>

    <ImageView android:id="@+id/list_item_dopinfo1_image"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_below="@+id/stub_for_alt_name"
               android:src="@drawable/ic_released"/>

</RelativeLayout>

ViewStub を TextView の下に、ImageView を ViewStub の下に配置します。

ViewStub が膨らんだ要素は、期待どおりに表示されます。ただし、ViewStub を持たない要素には TextView と ImageView が重なっています。

レイアウトの何が問題になっていますか?

アップデート:

私が見つけた唯一の解決策は、ViewStub と関連する TextView に同じandroid:id値を与えることです。

4

4 に答える 4

5

私が見つけた唯一の解決策は、ViewStub と関連する TextView に同じandroid:id値を与えることです。

于 2012-10-29T09:13:54.147 に答える
3

それは古い質問ですが、便利な追加があります

1)はい、他の人が投稿したように-同じものidを使用してinflatedIdください:

<ViewStub 
   android:id="@+id/view_stub_id"
   android:inflatedId="@id/view_stub_id"
   ... 
/>

2)ビュー を拡張したり、コンテンツを更新したり する必要がある場合は、次のようにすると便利です。

    View v = parentView.findViewById(R.id.view_stub_id);
    if (v instanceof ViewStub)
        v = ((ViewStub) v).inflate();

    // here v is always the inflated view
    // ...
于 2015-01-24T20:38:07.407 に答える
1
Hi you can try this one.

<RelativeLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/list_item_bottom">

//you can add another relative layout containing your textview and imageview
  <RelativeLayout
        android:id="@+id/layout_content" 
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >


        <TextView android:id="@+id/list_item_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

         <ImageView android:id="@+id/list_item_dopinfo1_image"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_below="@+id/stub_for_alt_name"
             android:src="@drawable/ic_released"
             android:layout_below="@+id/list_item_name" />

</RelativeLayout>

<ViewStub android:id="@+id/stub_for_alt_name"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_below="@+id/list_item_name"
          android:layout="@layout/text_view_alt_name"
          android:layout_below="@+id/layout_content" />

</RelativeLayout>
于 2012-10-24T09:09:03.950 に答える