The following is my code. I want an interface where I have a single line textbox, a multiline textbox with 2 buttons bel开发者_Python百科ow. 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
I was curious how to do this, so I decided to try it out. This was what I came up with:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/buttons"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="@+id/okbutt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="OK" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
<TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Name" />
<EditText
android:id="@+id/textedit1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textview1" />
<TextView
android:id="@+id/textview2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textedit1"
android:text="Contents" />
<EditText
android:id="@+id/textedit2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/textview2"
android:layout_above="@id/buttons" />
</RelativeLayout>
It seems to do what you want.
you can use relative layout here instead of two linear layouts,i think it will give more clear ui. and
if u want to increase height of button manually just increase the height of text written on button, i.e. height of OK and cancel with
android:textSize
try this, may be this one helps you.
精彩评论