2012-09-20 42 views
0

在我的佈局中,我需要一個標題,一個列表視圖和一個包含TextView的頁腳。 TextView需要調整大小到5行。認爲Facebook聊天,在那裏你必須與你的朋友的名字,中間的內容窗格和樓下一個文本框的藍色標題,一種生長在您鍵入的東西在:使用2個調整大小視圖創建Android佈局

[header]  a fragment that takes up about 50dp 
[content] 
[content] 
[content] 
[content] something like a ViewGroup with a ListView in it 
[content] 
[content] 
[content] 
[footer]  a ViewGroup that contains an EditText and Buttons 

我已經試過各種不同的佈局設置,但不能正確。頁腳佔用所有空間,或內容覆蓋頁腳。

這是我到目前爲止有:

<LinearLayout ...> 

    <!-- Slot to put Header fragment in --> 
    <FrameLayout 
     android:id="@+id/header" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <!-- Here's where the content goes. This is supposed to be a ListView 
     inserted as a fragment --> 
    <FrameLayout 
     android:id="@+id/content" 
     ... /> 

    <include 
     android:id="@+id/footer" 
     ... /> 

</LinearLayout> 

我離開了layout_widthlayout_height值空,因爲我不知道如何設置他們。

最新通報 起初,我以爲這個問題是因爲我EditText設置爲maxLines=5TextMultiline,但我想用一個硬編碼的高度去除一切,但一個按鈕,插入還是覆蓋了一切。我也試着設置<footer below="content">但隨後content只是覆蓋footer

+0

嗨..看我的答案,如果它可以幫助您 – Shruti

+0

您是否至少嘗試過我的佈局文件?我真的懷疑它的行爲像你在問題中所說的那樣。 – Luksprog

回答

1

的問題是,所述footer佈局包括的是另一個RelativeLayoutfooter佈局包含設置layout_alignParentBottom="true"的元素,這使得頁腳佈局佔據了整個屏幕。我不知道爲什麼它會那樣做,但是那會發生。

0

要創建這樣的UI創建佈局

header.xml

<?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="wrap_content" 
    android:orientation="horizontal" > 

<TextView 

      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingLeft="5dp" 
      android:text="xyz" 
      android:textSize="10dp" /> 
</LinearLayout> 

的頁腳:

footer.xml

<?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="wrap_content" 
    android:orientation="horizontal" > 

<EditText 

      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingLeft="5dp" 
      android:text="xyz" 
      android:textSize="10dp" /> 
</LinearLayout> 

創建另一個佈局將包含ListView的,你說: main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_gravity="center" 
android:gravity="center" 
android:orientation="vertical" > 
**<include layout="@layout/header.xml" android:layout_alignParentTop="true"/>** 
<ListView 
     android:id="@+id/listview" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:clickable="true" 
     > 
    </ListView> 
**<include layout="@layout/footer.xml" android:layout_below="@+id/listview" android:layout_alignParentBottom="true"/>** 
</RelativeLayout> 
+0

對不起,但你目前的答案涵蓋了'footer'。 – cesar

+0

@ceaser:嘗試在相對佈局中設置'android:layout_marginBottom =「50dip」'。請參閱我編輯的答案 – Shruti

+0

這顯示了底部的'header','content'和50dp間隔。頁腳仍然不存在。我的假設是,「footer」也移動了50dp,而「content」恰好覆蓋了它。 – cesar

0

檢查這個...我希望它幫助。目前,我已經在Values文件夾中爲ListView定義了一個array.xml,其中有一些空的條目。你將不得不用代碼來處理它。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 


     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="HEADER" />  

     <ListView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:entries="@array/chats" 
      android:layout_weight="1"> 

     </ListView> 


     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:lines="5" 
      android:inputType="textMultiLine" 
      android:hint=" Please enter your Chat" /> 

</LinearLayout> 
相關問題