【发布时间】:2016-11-29 16:02:58
【问题描述】:
我想以编程方式设置 PercentFrameLayout 的子视图的高度/宽度。如何在运行时设置 PercentFrameLayout 子视图的百分比高度/宽度..
【问题讨论】:
标签: android
我想以编程方式设置 PercentFrameLayout 的子视图的高度/宽度。如何在运行时设置 PercentFrameLayout 子视图的百分比高度/宽度..
【问题讨论】:
标签: android
我假设您的 PercentLayout 中有 ID 为 view_child 的 View。
所以使用这个代码sn-p
View view = findViewById(R.id.view_child);
PercentRelativeLayout.LayoutParams params =(PercentRelativeLayout.LayoutParams) view.getLayoutParams();
// This will currently return null, if view not exist in your xml.
PercentLayoutHelper.PercentLayoutInfo info = params.getPercentLayoutInfo();
info.heightPercent = 0.60;
view.requestLayout();
希望对您有所帮助..
【讨论】:
ImageView child= new ImageView(getActivity());
percentRelativeLayout.addView(child);
PercentRelativeLayout.LayoutParams params = (PercentRelativeLayout.LayoutParams) child.getLayoutParams();
PercentLayoutHelper.PercentLayoutInfo info = params.getPercentLayoutInfo();
info.heightPercent = 0.05f;
info.widthPercent = 0.05f;
info.leftMarginPercent = 0.5f;
child.setLayoutParams(params);
【讨论】: