I need to create text field which takes 70% of layout’s width (in linear layout). I use this code:
<EditText
android:id="@+id/phone"
android:layout_width="fill_parent"
android:layout_weight=".7"
android:layout_height="wrap_content"
android:inputType="phone" >
The problem is that in such case height also takes 70% of layout’s height – but I don’t need to change it, just want it to be “wrap_content”. Is there any good solution?
UPD:
Would it be a good solution if I create a new horizontal-orientated linear layout and place my text field inside it? Or maybe something more elegant?
UPD(2):
I want it to look like below, but without using marginLeft and marginRgiht, which would give different percentage on a different screen resolution

You need to set
weightSumon the parent of the control if you intend to use the weight. So yeah, put it in a LinearLayout and give the layout the proper parameters. Also, please remember that weight only affects the EXTRA space, so you want to set the width to 0dp, so the entire available space is considered “extra” space. Lastly, I think using integers for weight might be faster, but I’m not sure about that.UPDATE:
If you want it centered as well, then include some spacer views to the left and to the right, with the proper weights: