Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java PercentRelativeLayout,如何以编程方式设置高度_Java_Android_Android Relativelayout_Android Percent Library - Fatal编程技术网

Java PercentRelativeLayout,如何以编程方式设置高度

Java PercentRelativeLayout,如何以编程方式设置高度,java,android,android-relativelayout,android-percent-library,Java,Android,Android Relativelayout,Android Percent Library,我使用的是android percent support软件包中的PercentRelativeLayout。这就是我的布局 <android.support.percent.PercentRelativeLayout android:id="@+id/view_parent" app:layout_heightPercent="68%" android:visibility="invisible" android:layout_width="match_paren

我使用的是android percent support软件包中的PercentRelativeLayout。这就是我的布局

<android.support.percent.PercentRelativeLayout
    android:id="@+id/view_parent"
    app:layout_heightPercent="68%" android:visibility="invisible"
    android:layout_width="match_parent"
    android:background="@color/mountain_meadow" android:layout_alignParentTop="true"
    android:layout_height="wrap_content">


    <View android:id="@+id/view_child" android:layout_width="match_parent" app:layout_heightPercent="30%"
        android:layout_alignParentBottom="true"
        />

</android.support.percent.PercentRelativeLayout>


我想以编程方式更改
查看\u child
的高度。如何使用
PercentRelativeLayout.LayoutParams
或任何其他方法来完成此操作。

是否要设置新的百分比值?如果是,您需要:

View view = findViewById(R.id.view_child);
PercentRelativeLayout.LayoutParams params = (PercentRelativeLayout.LayoutParams) view.getLayoutParams();
// This will currently return null, if it was not constructed from XML.
PercentLayoutHelper.PercentLayoutInfo info = params.getPercentLayoutInfo();
info.heightPercent = 0.60f;
view.requestLayout();

如何设置没有百分比的另一个值?例如,dp中的marginBottom,使用百分比布局参数?您好@gruszczy,您知道为什么我总是将百分比布局信息设置为“null”吗?请帮助我。您好@gruszczy,根据您的注释“//如果它不是从XML构造的,则当前将返回null。”。请帮助我将其添加到XML中