Android - Linear Layout arrangement, not positioning as expected
Posted
by
Arun
on Stack Overflow
See other posts from Stack Overflow
or by Arun
Published on 2010-12-23T08:29:08Z
Indexed on
2010/12/23
13:53 UTC
Read the original article
Hit count: 400
The following is my code. I want an interface where I have a single line textbox, a multiline textbox with 2 buttons below. I want the multiline textbox to occupy all the space available after rendering the buttons and textbox. For this I created two LinearLayouts inside the main layout. The first one has vertical orientation with layout_width set to fill_parent. The second one is horizontal with fill_parent again.
The first one has a textbox for which I have set the layout_height to fill parent. The second one has two textboxes OK and Cancel.
When I run this application I get the UI, but the Buttons are very small (about 5px in height). I have to set the button height manually. What am I doing wrong here. I don't want to hard code the button height.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1">
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Name"></TextView>
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content"></EditText>
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Contents"></TextView>
<EditText android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="top" />
</LinearLayout>
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1">
<Button android:id="@+id/okbutt" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="OK" android:layout_weight="1" />
<Button android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="Cancel" android:layout_weight="1" />
</LinearLayout>
Thanks, Arun
© Stack Overflow or respective owner