[英]PercentRelativeLayout, how to set the height programmatically
我正在使用來自android percent支持包的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>
我想以編程方式更改view_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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.