0

我想創建一個Android屏幕布局,我認爲它非常簡單。我基本上需要頂部的頁眉和底部的頁腳,以及填充屏幕空間其餘部分的EditText框。標題和EditText框工作正常,但我似乎無法讓我的頁腳顯示。這裏是我的代碼:Android佈局問題

<?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> 

就像我說過的,除了我的頁腳,一切都正常。誰能告訴我我做錯了什麼?

回答

2

您的佈局對於您想要實現的內容太複雜。除非您絕對必須使用它,否則我會建議您避免使用RelativeLayout

下面是如何創建使用LinearLayout頭/內容/頁腳佈局一個簡單的例子:
(注意在content元素layout_weight

<?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>   

enter image description here

+0

這解決了我的問題。感謝您簡化我的過度工程 – Icemanind 2011-05-14 21:56:40

0

如果我理解正確的,你的佈局的一部分,是頁眉和頁腳,加入這一行:

android:layout_above="@+id/linearLayout1" 

到的EditText

2

似乎有很多額外的不必要的佈局。這將爲您佈置三個區域,您可以將任何內容放入它們中,或者只是將它們視爲控件。每個區域的高度將分別爲25%,50%,25%。如果您不想要百分比,請從頁眉和頁腳中刪除重量並設置它們的寬度值,但保留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>