Rahul Rastogi
Rahul Rastogi

Reputation: 4698

How to set the percentage height/width of child views of PercentFrameLayout at runtime

I want to set the child view's height/width of PercentFrameLayout programmatically. How to set the percentage height/width of child views of PercentFrameLayout at runtime..

Upvotes: 2

Views: 1649

Answers (2)

Bosco Sabin
Bosco Sabin

Reputation: 124

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

Upvotes: 0

Setmax
Setmax

Reputation: 1034

I assume that you have View with Id view_child inside of your PercentLayout.

so use this code snippet

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

hope this help..

Upvotes: 9

Related Questions