我有一个RelativeLayout一个PercentRelativeLayout内如下面的代码显示的RelativeLayout不扩大,以填补父时的观点被添加到父
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<RelativeLayout
android:id="@+id/clickBox"
android:layout_height="match_parent"
android:background="@color/PaleBlack"
android:fillViewport="true"
app:layout_widthPercent="35%">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:scaleX="0.8"
android:scaleY="0.8"
android:src="@mipmap/ic_open"/>
</RelativeLayout>
</android.support.percent.PercentRelativeLayout>
但是,如果我然后以编程方式将一个TextView添加到PercentRelativeLayout
,则RelativeLayout
不会扩展垂直填充父项PercentRelativeLayout
,然后结果如下所示
我该如何解决这个问题,以便RelativeLayout
填充父母的身高?
难道不清楚吗? RelativeLayout **不会**展开(至少,如果您设置了'android:layout_width =“match_parent”')。 ImageView **不**。 –
@ModularSynth不,我把一个黑色的背景来确保它不会扩展 –
@TimCastelijns不幸的是没有第二个XML。视图是在布局绘制后通过代码动态添加的 –