g.r*_*ion 29 java android android-relativelayout android-percent-library
我正在使用来自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>
Run Code Online (Sandbox Code Playgroud)
我想以view_child
编程方式更改高度.我怎么能用它PercentRelativeLayout.LayoutParams
或任何其他方式做到这一点.
gru*_*czy 68
您想设置新的百分比值吗?如果是,您需要:
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();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7593 次 |
最近记录: |