fifth
fifth

Reputation: 4349

How to set fixed size and position of a RelativeLayout?

Android implemented a default layout rule, like measure, layout, etc, I didn't find out there is a method to set such a fixed size. How to get rid of that default layout behavior?

Actually, in my case, every view is supposed to be relative to its parent, and will have a specified size., how could I do?

Thx

Upvotes: 1

Views: 8348

Answers (1)

Zelimir
Zelimir

Reputation: 11028

Not sure if I correctly understood your issue, but you can specify size of certain View (e.g. RelativeLayout, LinearLayout or certain control). In Properties of your layout view (Layout width, Layout height) you do not need to use only wrap_content or fill_parent. You are also allowed to type size like 40dip.

If you created your View dinamically, then you should set LayoutParams. For example, to define your element size and margins for RelativeLayout (similar for others) you should use something like:

RelativeLayout.LayoutParams adaptLayout = new RelativeLayout.LayoutParams(element_width, element_height);
adaptLayout.setMargins(marginLeft, marginTop, marginRight, marginBottom);
mLinearLayoutForm.setLayoutParams(adaptLayout);             

Upvotes: 3

Related Questions