2
我想以編程方式設置子視圖的PercentFrameLayout高度/寬度。如何在運行時設置PercentFrameLayout的子視圖的百分比高度/寬度..如何在運行時設置PercentFrameLayout子視圖的百分比高度/寬度
我想以編程方式設置子視圖的PercentFrameLayout高度/寬度。如何在運行時設置PercentFrameLayout的子視圖的百分比高度/寬度..如何在運行時設置PercentFrameLayout子視圖的百分比高度/寬度
我假設您的PercentLayout中包含View with ID view_child。
所以使用這個代碼片斷
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);