RelativeLayout和ViewStub膨胀

RelativeLayout和ViewStub膨胀

本文介绍了RelativeLayout和ViewStub膨胀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的布局如下.

<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之下.

I want ViewStub to be below TextView and ImageView to be below ViewStub.

ViewStub膨胀的元素如我预期的那样显示.但是没有ViewStub的元素的TextView与ImageView重叠.

Elements with ViewStub inflated are shown as I expect.But elements without ViewStub have TextView overlapped with ImageView.

我的布局出了什么问题?

What's wrong with my layout?

更新:

我发现的唯一解决方案是为ViewStub和相关的TextView赋予相同的android:id值.

The only solution I've found is to give ViewStub and related TextView the same android:id value.

推荐答案

我发现的唯一解决方案是为ViewStub和相关的TextView赋予相同的android:id值.

The only solution I've found is to give ViewStub and related TextView the same android:id value.

这篇关于RelativeLayout和ViewStub膨胀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 16:35