Android 在滚动视图中使用listview时,主视图中缺少页脚菜单
我在主视图中有一个滚动视图,下面我有一个页脚菜单,如选项卡栏。现在我需要在卷轴中放置一个listview。要做到这一点,我遵循Android 在滚动视图中使用listview时,主视图中缺少页脚菜单,android,android-layout,listview,scrollview,footer,Android,Android Layout,Listview,Scrollview,Footer,我在主视图中有一个滚动视图,下面我有一个页脚菜单,如选项卡栏。现在我需要在卷轴中放置一个listview。要做到这一点,我遵循 公共类实用程序{ 公共静态无效setListViewHeightBasedOnChildren(ListView ListView){ ListAdapter ListAdapter=listView.getAdapter(); 如果(listAdapter==null){ //前提条件 返回; } int totalHeight=listView.getPaddin
公共类实用程序{
公共静态无效setListViewHeightBasedOnChildren(ListView ListView){
ListAdapter ListAdapter=listView.getAdapter();
如果(listAdapter==null){
//前提条件
返回;
}
int totalHeight=listView.getPaddingTop()+listView.getPaddingBottom();
对于(int i=0;i
有了这个,我得到了一个理想的视图,但是当我加载带有一些数据的列表时,主视图中的页脚菜单丢失了
我怎样才能解决这个问题
更新:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/botom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#fff"
android:gravity="bottom"
android:layout_alignParentBottom="true" >
<include layout="@layout/footer" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/botom">
主XML
和Footer.xml
您需要告诉程序您的滚动视图应该在页脚上方。 为此,, 给你的线性布局加上一些id,让它像你的页脚一样
<LinearLayout
android:id="@+id/footer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="bottom"
android:background="#fff"
android:gravity="bottom"
>
<include layout="@layout/footer" />
并给予
android:layout_over=“@+id/footer”
在您的滚动视图中。//请尝试这种方式
// try this way
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/logo_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="100" >
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:contentDescription="@string/app_name"/>
<LinearLayout
android:id="@+id/title_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@drawable/titleredbg"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/search_title"
android:textColor="#fff"
android:textSize="20sp" />
</LinearLayout>
<ImageView
android:id="@+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:contentDescription="@string/app_name"
android:padding="5dp"/>
<TextView
android:id="@+id/hr1"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#D2D2D2" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff" >
<Button
android:id="@+id/category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="31dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/occassion_name"
android:background="@drawable/searchdropdown"
android:textColor="#686868"
android:singleLine="true"
android:ellipsize="marquee"
android:maxEms="5"
android:scrollHorizontally="true"
android:text="NONONONONON nNONONNO "/>
<TextView
android:id="@+id/or_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/category"
android:layout_below="@+id/category"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:text="@string/or"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#C11312" />
<TextView
android:id="@+id/occassion_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/category"
android:layout_alignParentLeft="true"
android:layout_marginLeft="20dp"
android:text="@string/search_product_text"
android:textColor="#686868" />
<Button
android:id="@+id/brand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/or_text"
android:layout_below="@+id/or_text"
android:background="@drawable/searchdropdown"
android:textColor="#686868" />
<TextView
android:id="@+id/search_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/occassion_name"
android:layout_below="@+id/brand"
android:layout_marginTop="10dp"
android:text="@string/sort"
android:textColor="#686868" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/search_price"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="100" >
<CheckBox
android:id="@+id/price_level_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="25"
android:button="@drawable/checkbox_xml"
android:paddingLeft="20dp"
android:textColor="#686868"
android:textSize="12sp" />
<CheckBox
android:id="@+id/price_level_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="25"
android:button="@drawable/checkbox_xml"
android:paddingLeft="20dp"
android:textColor="#686868"
android:textSize="12sp" />
<CheckBox
android:id="@+id/price_level_3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="25"
android:button="@drawable/checkbox_xml"
android:paddingLeft="20dp"
android:textColor="#686868"
android:textSize="12sp" />
<CheckBox
android:id="@+id/price_level_4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="25"
android:button="@drawable/checkbox_xml"
android:paddingLeft="20dp"
android:textColor="#686868"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:id="@+id/wish_list_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/search_price"
android:layout_below="@+id/linearLayout1"
android:layout_marginTop="10dp"
android:text="@string/search_wishlist"
android:textColor="#686868" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/wish_list_text"
android:layout_alignBottom="@+id/wish_list_text"
android:layout_alignLeft="@+id/brand"
android:background="@drawable/searchdropdown" />
<Button
android:id="@+id/go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/button3"
android:layout_below="@+id/button3"
android:layout_marginTop="10dp"
android:background="@drawable/gobtn" />
<TextView
android:id="@+id/hr2"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@+id/go"
android:layout_marginTop="5dp"
android:background="#D2D2D2" />
</RelativeLayout>
<LinearLayout
android:id="@+id/container_2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector"
android:visibility="visible" />
<LinearLayout
android:id="@+id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="#fff" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="@string/no_products"
android:textColor="#000" >
</TextView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
<include layout="@layout/footer"
android:background="#fff"/>
</LinearLayout>
只需将此代码替换为您的代码:
您的根布局将是相对的。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/botom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#fff"
android:gravity="bottom"
android:layout_alignParentBottom="true" >
<include layout="@layout/footer" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/botom">
包含页脚的线性布局如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/botom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#fff"
android:gravity="bottom"
android:layout_alignParentBottom="true" >
<include layout="@layout/footer" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/botom">
对于滚动视图:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/botom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#fff"
android:gravity="bottom"
android:layout_alignParentBottom="true" >
<include layout="@layout/footer" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/botom">
请发布您的布局