I am trying to create an Android screen layout that I think is pretty simple. I basically want a header at the top and a footer at the bottom, along with an EditText box that fills the rest of the screen space. The header and EditText box is working fine, but I cannot seem to get my footer to display. Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView android:id="@+id/imageView1"
android:src="@drawable/droidiary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
</ImageView>
<View android:id="@+id/view1"
android:layout_height="2dip"
android:background="#FFAAAAFF"
android:layout_width="wrap_content">
</View>
<RelativeLayout android:id="@+id/rlLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:inputType="text|textMultiLine"
android:layout_alignParentTop="true"
android:hint="Type about your day..."
android:text=""
android:id="@+id/txtEntry"
android:layout_height="match_parent"
android:layout_width="match_parent">
</EditText>
<LinearLayout android:layout_alignParentBottom="true"
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View android:id="@+id/view2"
android:layout_height="2dip"
android:background="#FFAAAAFF"
android:layout_width="wrap_content">
</View>
<TextView android:text="TextView"
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Like I said, everything开发者_如何学Go works except my footer. Can anyone tell me what I'm doing wrong?
Your layout is too complicated for what you want to achieve. I would recommend to avoid RelativeLayout
unless you absolutely have to use it.
Here is a simple example of how to create header/content/footer layout using LinearLayout
:
(note the layout_weight
in the content
element)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Header" />
<EditText
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:singleLine="false"
android:hint="Type about your day..."
android:text="" >
</EditText>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Footer" />
</LinearLayout>
There seems to be a lot of extra unneeded layouts. This will layout the three areas for you and you can put anything inside them or just make them a view control. The height of each area will be 25%, 50%, 25%. If you don't want percentages, remove the weights from the header and footer and set their width value but leave the weight of the EditText.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View android:id="@+id/headerView"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="2" />
<EditText android:id="@+id/editBox"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" />
<View android:id="@+id/footerView"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="2" />
</LinearLayout>
If I correctly understood which part of your layout is header and footer, add this line:
android:layout_above="@+id/linearLayout1"
to EditText
精彩评论