2012-01-24 192 views
1

我正在开发使用android sdk v 2.1的Android应用程序。在一个页面上我正在合并不同的布局像头,页脚,列表视图等 我的代码是这样的:如何修复在底部使用包括不同布局在Android的单个布局中的底部底部

<?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" android:background="#FFFFFF"> 


    <com.myapp.LogoBarActivity 
       android:id="@+id/logobarLayout" android:layout_height="wrap_content" 
       android:layout_width="fill_parent"/> 

    <include layout="@layout/header_2"/>  
    <include layout="@layout/header_3"/> 

    <ListView android:id="@android:id/list" android:layout_width="fill_parent" 
       android:layout_height="wrap_content"></ListView> 

    <include layout="@layout/list_footer" /> 

</LinearLayout> 

但问题是,底部的按钮(布局=“@布局/ list_footer”)是在列表视图穿过屏幕时不显示。我想滚动列表视图 layout =“@ layout/header_3”和layout =“@ layout/list_footer”,所有的布局应该固定在屏幕上。请指导我。

+0

参考下后.. [http://stackoverflow.com/questions/8308983/button-after-listview-crashing-the-app-xml/ 8309134#8309134] [1] – Jayabal

回答

1

你应该使用RelativeLayout来得到你想要的。 XML代码将是这样的:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:background="#FFFFFF"> 


    <com.myapp.LogoBarActivity android:layout_alignParentTop="true" 
       android:id="@+id/logoBar" 
       android:id="@+id/logobarLayout" android:layout_height="wrap_content" 
       android:layout_width="fill_parent"/> 

    <include layout="@layout/header_2" android:id="@+id/header2" android:layout_below="@+id/logoBar"/>  
    <include layout="@layout/header_3" android:id="@+id/header3" android:layout_below="@+id/header2"/> 

    <ListView android:id="@android:id/list" android:layout_width="fill_parent" 
       android:layout_height="wrap_content" android:layout_above="@+id/footer" 
       android:layout_below="@+id/header3"/> 

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

</RelativeLayout> 
+0

正是这样。除了你需要把'ListView'放入'ScrollView'中以允许滚动。 – iTurki

+0

另外,从'android:layout_below'和'android:layout_above'中删除'+' – iTurki

+0

感谢您的回复,但我已经试过这段代码。当我使用此代码时,页脚底部显示,列表视图覆盖整个屏幕,方法是在顶部覆盖header_3,而logo-bar和header_2不显示在屏幕上。简单来说,这扰乱了整个布局。 –