本文介绍了PercentRelativeLayout,如何以编程方式设置高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用来自Android百分比支持包的PercentRelativeLayout.这就是我的布局.

I am using PercentRelativeLayout from android percent support package. this is what I have in my layout.

<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>

我想以编程方式更改view_child的高度.如何使用PercentRelativeLayout.LayoutParams或任何其他方式来做到这一点.

I want to change the height of view_child programmatically. How can I do that using PercentRelativeLayout.LayoutParams or any other way.

推荐答案

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

Do you want to set a new percentage value? If yes, you need to:

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();

这篇关于PercentRelativeLayout,如何以编程方式设置高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-27 08:50