I'm trying to create a FrameLayout
programmatically as follows(this view will float on the the bottom center of a LinearLayout
):
FrameLayout bottomFrameLayout = new FrameLayout(context);
bottomFrameLayout.setLayoutParams(new FrameLayout.LayoutParams(0,LayoutParams.FILL_PARENT,Gravity.CENTER | Gravity.BOTTOM));
Since I set layout_width=0dp
, I would like to also set layout_weight
to control the width. How can I do that?
You need to use LinearLayout.LayoutParams (int width, int height, float weight)
constructor since FrameLayout
is child of LinearLayout
therefore you are setting params for child in LinearLayout
.
Edit:
FrameLayout bottomFrameLayout = new FrameLayout(context);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0,LayoutParams.FILL_PARENT,mWeight);
lp.gravity = Gravity.CENTER | Gravity.BOTTOM;
bottomFrameLayout.setLayoutParams(lp);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.