2014-10-31 192 views
-1

這是我的layout.xml,我想在listview的底部添加一個固定的頁腳。另外,我不能更改當前的佈局。此佈局在頂部包含一個操作欄。第一個相對佈局包含所有佈局,包括動作欄相對佈局,以下我有一個包含listview的框架佈局。我希望這個列表視圖有一個固定在包含一些圖像按鈕的底部的頁腳。如何將頁腳添加到佈局?

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <!-- This acts as Actionbar --> 
    <RelativeLayout 
     android:id="@+id/relativeLayout" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:paddingRight="10dp" 
     android:orientation="horizontal" 
     android:background="@drawable/action_bar_background_strip" > 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="20dp" 
      android:clickable="true" 
      android:onClick="toggleMenu" 
      android:contentDescription="@null" 
      android:src="@drawable/drawer_toggle_button" /> 

     <View 
      android:id="@+id/View1" 
      android:layout_width="1dp" 
      android:layout_height="fill_parent" 
      android:layout_marginLeft="20dp" 
      android:layout_toRightOf="@+id/imageView1" 
      android:background="#ffffff" /> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:layout_toRightOf="@+id/View1" 
      android:layout_marginTop="8dp" 
      android:layout_marginLeft="20dp" 
      android:layout_marginRight="115dp" 
      android:text="Listview" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textColor="#ffffff" 
      android:textStyle="bold" /> 

     <View 
      android:id="@+id/View2" 
      android:layout_width="1dp" 
      android:layout_height="fill_parent" 
      android:layout_toRightOf="@+id/textView1" 
      android:background="#ffffff" /> 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:contentDescription="@null" 
      android:src="@drawable/icon" /> 

    </RelativeLayout> 

    <FrameLayout 
     android:layout_below="@+id/relativeLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <ListView 
      android:id="@+id/listView" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:choiceMode="multipleChoice" > 
     </ListView> 

    </FrameLayout> 

回答

0

例如,您可以:爲您footer創建新的佈局,並將其放置在其母公司的底部,使您的FrameLayout以上的footer

使用android:layout_aboveandroid:layout_alignParentBottom性質placet你的佈局...

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"> 

<!-- This acts as Actionbar --> 
<RelativeLayout 
    android:id="@+id/relativeLayout" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:paddingRight="10dp" 
    android:orientation="horizontal" 

    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true"> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:layout_marginLeft="20dp" 
     android:clickable="true" 
     android:onClick="toggleMenu" 
     android:contentDescription="@null" /> 

    <View 
     android:id="@+id/View1" 
     android:layout_width="1dp" 
     android:layout_height="fill_parent" 
     android:layout_marginLeft="20dp" 
     android:layout_toRightOf="@+id/imageView1" 
     android:background="#ffffff" /> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_toRightOf="@+id/View1" 
     android:layout_marginTop="8dp" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="115dp" 
     android:text="Listview" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#ffffff" 
     android:textStyle="bold" /> 

    <View 
     android:id="@+id/View2" 
     android:layout_width="1dp" 
     android:layout_height="fill_parent" 
     android:layout_toRightOf="@+id/textView1" 
     android:background="#ffffff" /> 

    <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:contentDescription="@null" /> 

</RelativeLayout> 

<FrameLayout 
    android:layout_below="@+id/relativeLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@+id/linearLayout"> 

    <ListView 
     android:id="@+id/listView" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:choiceMode="multipleChoice"> 
    </ListView> 
</FrameLayout> 


<LinearLayout 
    android:orientation="horizontal" 
    android:layout_alignParentBottom="true" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:id="@+id/linearLayout"> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="New Button" 
     android:id="@+id/button" /> 
</LinearLayout> 

+0

我想你的方式,但線性佈局是透明的, listview從線性佈局按鈕的背景中顯示。 – 2014-10-31 10:04:53

+0

爲listview使用layout_above屬性併爲其賦予頁腳線性佈局的id。這將解決您的問題。 – 2014-12-09 04:44:06

0

做一個footer.xml象下面這樣:

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="50dp" 
    android:background="#5E616B" 
    android:gravity="center_horizontal" 
    android:orientation="horizontal" 
    android:weightSum="1" > 

    <ImageButton 
     android:id="@+id/btn_one" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_marginLeft="15dp" 
     android:layout_marginTop="2dp" 
     android:layout_weight=".2" 
     android:background="@drawable/footer_button_pressed" 
     android:src="@drawable/pingicon" /> 

    <ImageButton 
     android:id="@+id/btn_two" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_marginLeft="15dp" 
     android:layout_marginTop="2dp" 
     android:layout_weight=".2" 
     android:background="@drawable/footer_button_pressed" 
     android:src="@drawable/profile" /> 

    <ImageButton 
     android:id="@+id/btn_three" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_marginLeft="15dp" 
     android:layout_marginTop="2dp" 
     android:layout_weight=".2" 
     android:background="@drawable/footer_button_pressed" 
     android:src="@drawable/mycircle" /> 

    <ImageButton 
     android:id="@+id/btn_four" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_marginLeft="15dp" 
     android:layout_marginTop="2dp" 
     android:layout_weight=".2" 
     android:background="@drawable/footer_button_pressed" 
     android:src="@drawable/sendping" /> 

    <ImageButton 
     android:id="@+id/btn_five" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_marginLeft="15dp" 
     android:layout_marginTop="2dp" 
     android:layout_weight=".2" 
     android:background="@drawable/footer_button_pressed" 
     android:src="@drawable/settings" /> 
</LinearLayout> 

這裏的想法是simple.Take與weightsum 1的線性佈局,並分割重量他們的孩子。在這裏我已經拍攝了5個圖像按鈕並分配了兩個重量。不要忘了將佈局方向設置爲垂直。

然後包括頁腳在你的佈局,如:

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

然後設計自己的滾動型爲:

<FrameLayout 
     android:layout_below="@+id/relativeLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/footer" 
     android:layout_below="@+id/header"(IF ANY) > 

     <ListView 
      android:id="@+id/listView" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:choiceMode="multipleChoice" > 
     </ListView> 

    </FrameLayout> 
0
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/relativeLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <ListView 
     android:id="@+id/listView1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/linearLayout1" > 
    </ListView> 

<!-- Footer linear layout --> 

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="55dp" 
     android:weightSum="5" 
     android:layout_marginBottom="-5dp" 
     android:orientation="horizontal" 
     android:layout_alignParentBottom="true" > 

     <ImageButton 
      android:id="@+id/imageButton1" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:layout_marginLeft="-4.5dp" 
      android:layout_marginRight="-4dp" 
      android:layout_marginTop="-5dp" 
      android:contentDescription="@null" 
      android:src="@drawable/filing_button_icon" /> 

     <ImageButton 
      android:id="@+id/imageButton2" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:layout_marginLeft="-4.5dp" 
      android:layout_marginRight="-4.5dp" 
      android:layout_marginTop="-5dp" 
      android:contentDescription="@null" 
      android:src="@drawable/delete_icon" /> 

     <ImageButton 
      android:id="@+id/imageButton3" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:layout_marginLeft="-4dp" 
      android:layout_marginRight="-4.5dp" 
      android:layout_marginTop="-5dp" 
      android:contentDescription="@null" 
      android:src="@drawable/reply_all_icon" /> 

     <ImageButton 
      android:id="@+id/imageButton4" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:layout_marginLeft="-4dp" 
      android:layout_marginRight="-4.5dp" 
      android:layout_marginTop="-5dp" 
      android:contentDescription="@null" 
      android:src="@drawable/reply_icon" /> 

     <ImageButton 
      android:id="@+id/imageButton5" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:layout_marginLeft="-4dp" 
      android:layout_marginRight="-4.5dp" 
      android:layout_marginTop="-5dp" 
      android:contentDescription="@null" 
      android:src="@drawable/forward_icon" /> 

    </LinearLayout> 

</RelativeLayout>