Android 需要在顶部和底部栏之间显示项目列表,

Android 需要在顶部和底部栏之间显示项目列表,,android,android-layout,Android,Android Layout,我想创建一个布局,其中有两个栏,一个在顶部,另一个在底部,两个栏之间有一个listview,但这里的问题是,在顶部和底部栏之间,我需要显示项目列表,顶部和底部栏都在它们的位置,只有listview可以滚动 下面是我的xml布局,很抱歉问题太长,如有任何建议,我们将不胜感激。谢谢 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_paren

我想创建一个布局,其中有两个栏,一个在顶部,另一个在底部,两个栏之间有一个listview,但这里的问题是,在顶部和底部栏之间,我需要显示项目列表,顶部和底部栏都在它们的位置,只有listview可以滚动

下面是我的xml布局,很抱歉问题太长,如有任何建议,我们将不胜感激。谢谢

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="center_vertical"
    style="@android:style/ButtonBar"
>
    <ImageButton
        android:id="@+id/IBADDNEW"
        android:layout_width="62dp"
        android:layout_height="62dp"
        android:src="@drawable/ad_user_l" />

    <EditText
        android:id="@+id/ETSEARCHTEXT"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" >

        <requestFocus />
    </EditText>

    <ImageButton
        android:id="@+id/IBSEARCH"
          android:layout_width="62dp"
        android:layout_height="62dp"
        android:src="@drawable/search_64" />

</LinearLayout>

  <ScrollView 

    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:fillViewport="true"

>

      <LinearLayout
          android:id="@+id/LLforList"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:gravity ="center_vertical"
          android:orientation="horizontal" >

           <ImageView
          android:id="@+id/IVimageIcon"
          android:layout_width="60dp"
          android:layout_height="60dp"
          android:src="@drawable/ic_farmer" />

      <TextView
          android:id="@+id/TVFLNAME"
          android:layout_width="match_parent"
          android:layout_height="80dp"
          android:text="Some Name"
          android:textAppearance="?android:attr/textAppearanceMedium" />
      </LinearLayout>

  </ScrollView>

  <RelativeLayout
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/blankbarbottom"
    android:layout_alignParentBottom="true" >


    <LinearLayout
        android:id="@+id/FLlayoutLIst"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/btnMainMenu"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:src="@drawable/mainmenu_on" />

        <ImageView
            android:id="@+id/btnSettings"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:src="@drawable/settings_off" />

        <ImageButton
            android:id="@+id/btnExit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:src="@drawable/exit_off" />
    </LinearLayout>
</RelativeLayout>


为列表使用列表视图。它是可滚动的,因此您不需要滚动视图。请参阅,了解如何将简单ListView与适配器一起使用


您还应该为选项卡使用TabHost。查看一下

我想你可以使用listView.addheadview和listView.addrootview 编辑:

<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout 
android:layout_width="fill_parent" 
android:layout_alignParentTop="true"
android:layout_height="36dip" 
android:orientation="horizontal"
android:background="@drawable/cloth_xixian_bg"
android:id="@+id/headclothesroom">
<Button   android:id="@+id/redianroom"
    android:layout_width="100dip" 
    android:layout_height="36dip" 
    android:layout_marginLeft="40dip"
    android:background="@null"
    android:textSize="18sp"
     android:textColor="@drawable/color_wenzi_bg"
    android:text="热点排行"/>
 <Button   android:id="@+id/liangyiroom"
    android:layout_width="100dip" 
    android:layout_height="36dip"
    android:textColor="@drawable/color_wenzi_bg"
    android:textSize="18sp"
    android:background="@null"
    android:layout_marginLeft="25dip"
    android:text="我的靓衣间" />  




您可以创建一个布局,将其添加为ListView的
页眉
页脚
,然后将其添加到ListView

View header = getLayoutInflater().inflate(R.layout.header, null);
View footer = getLayoutInflater().inflate(R.layout.footer, null);
ListView listView = getListView();
listView.addHeaderView(header);
listView.addFooterView(footer);
setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_single_choice,
                android.R.id.text1, names));
View header=getLayoutInflater().充气(R.layout.header,null);
视图页脚=GetLayoutFlater()。充气(R.layout.footer,null);
ListView ListView=getListView();
addHeaderView(标题);
添加页脚视图(页脚);
setListAdapter(新阵列适配器)(此,
android.R.layout.simple\u list\u item\u单选,
android.R.id.text1,名称);

您需要为ListView项膨胀xml。使用以下代码创建新的xml say inflate.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/linearLayout1"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="horizontal"
  android:padding="5dp" >

    <ImageView
      android:id="@+id/imageView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginRight="5dp"
      android:src="@drawable/icon" >
    </ImageView>

    <TextView
      android:id="@+id/textView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="TextView" >
    </TextView>

</LinearLayout>
那么

使用任何适配器(如ArrayAdapter)扩展NewListAdapter类并执行此操作

class NewListAdapter extends ArrayAdapter {     
    Activity context;

    NewListAdapter(Activity context) {
        super(context, R.layout.inflate,items);
        this.context=context;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = context.getLayoutInflater();
        View row = inflater.inflate(R.layout.inflate, null);
        TextView lblName = (TextView) row.findViewById(R.id.textView1);
        lblName.setText(items[position]);
        return (row);
    }       
}

现在运行您的代码,看看神奇之处…

我自己做的,这就是原因的确切解决方案

在layour中,我添加了一个listView

        <ListView
        android:id="@+id/LVfarmerList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" >
    </ListView>

代替

       <ScrollView 

    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:fillViewport="true"

>

      <LinearLayout
          android:id="@+id/LLforList"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:gravity ="center_vertical"
          android:orientation="horizontal" >

           <ImageView
          android:id="@+id/IVimageIcon"
          android:layout_width="60dp"
          android:layout_height="60dp"
          android:src="@drawable/ic_farmer" />

      <TextView
          android:id="@+id/TVFLNAME"
          android:layout_width="match_parent"
          android:layout_height="80dp"
          android:text="Some Name"
          android:textAppearance="?android:attr/textAppearanceMedium" />
      </LinearLayout>

  </ScrollView>

并创建了另一个布局

   <LinearLayout
      android:id="@+id/LLforList"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:gravity ="center_vertical"
      android:orientation="horizontal" >

       <ImageView
      android:id="@+id/IVimageIcon"
      android:layout_width="60dp"
      android:layout_height="60dp"
      android:src="@drawable/ic_farmer" />

  <TextView
      android:id="@+id/TVFLNAME"
      android:layout_width="match_parent"
      android:layout_height="80dp"
      android:text="Some Name"
      android:textAppearance="?android:attr/textAppearanceMedium" />
  </LinearLayout>

现在创建了一个活动(不是listActivity)

其中我展示了布局,在顶部和底部栏之间有listview

并使用另一个布局创建了customAdapter,该布局具有一个imageview和textview


通过listview.setAdapter,将此适配器添加到列表视图中,它对我起了作用。

页眉和页脚不会停留在它们的位置。他们会滚动列表,是的。你应该考虑一下我的回答。。。您应该学会使用正确的UI元素。那么,如何使用简单的listview设置固定的栏,以及如何使用不同的行显示不同的图像呢。。我该如何实现它似乎很有帮助,我可以通过扩展BaseAdapter来创建listActivity和适配器吗?在同一个活动中,我可以执行您提到的以下操作。您可以在扩展listActivity的同一个类中创建扩展BaseAdapter的子类。谢谢Lalit,让我尝试一下,我试过了,但问题是,页眉和页脚没有固定,我想在顶部和底部的两个位置都添加固定条。
        <ListView
        android:id="@+id/LVfarmerList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" >
    </ListView>
       <ScrollView 

    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:fillViewport="true"

>

      <LinearLayout
          android:id="@+id/LLforList"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:gravity ="center_vertical"
          android:orientation="horizontal" >

           <ImageView
          android:id="@+id/IVimageIcon"
          android:layout_width="60dp"
          android:layout_height="60dp"
          android:src="@drawable/ic_farmer" />

      <TextView
          android:id="@+id/TVFLNAME"
          android:layout_width="match_parent"
          android:layout_height="80dp"
          android:text="Some Name"
          android:textAppearance="?android:attr/textAppearanceMedium" />
      </LinearLayout>

  </ScrollView>
   <LinearLayout
      android:id="@+id/LLforList"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:gravity ="center_vertical"
      android:orientation="horizontal" >

       <ImageView
      android:id="@+id/IVimageIcon"
      android:layout_width="60dp"
      android:layout_height="60dp"
      android:src="@drawable/ic_farmer" />

  <TextView
      android:id="@+id/TVFLNAME"
      android:layout_width="match_parent"
      android:layout_height="80dp"
      android:text="Some Name"
      android:textAppearance="?android:attr/textAppearanceMedium" />
  </LinearLayout>