необходимо отобразить список элементов между верхней и нижней панелью, - PullRequest
1 голос
/ 31 декабря 2011

Я хочу создать макет, в котором будут присутствовать две панели, одна сверху, другая снизу и одно представление списка между этими двумя барами. Но вопрос здесь заключается в том, что между верхней и нижней панелью мне нужно показать список элементов, где на их месте будут находиться как верхняя, так и нижняя полоса, будет прокручиваться только просмотр списка.

ниже мой макет 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>

Ответы [ 5 ]

1 голос
/ 31 декабря 2011

Вы можете создать Макет, который вы хотите добавить как Header и Footer 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));
1 голос
/ 31 декабря 2011

Используйте ListView для вашего списка. Это прокрутка, поэтому вам не нужно ScrollView. Обратитесь к http://developer.android.com/resources/tutorials/views/hello-listview.html, чтобы узнать, как использовать простой ListView с адаптером.

И вы также должны использовать TabHost для ваших вкладок. Посмотрите на http://developer.android.com/resources/tutorials/views/hello-tabwidget.html

0 голосов
/ 31 декабря 2011

Я сделал это сам, вот точное решение для причины,

в слое, я добавил один 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.setAdapter добавил этот адаптер в представление списка, и он работал для меня.

0 голосов
/ 31 декабря 2011

Вам нужно накачать xml для элементов ListView. Создайте новый xml скажем 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>

Теперь в вашем классе деятельности расширьте его с помощью ListActivity и сделайте это

Создайте строковый массив, скажем, "items" с несколькими "First L Name", как указано на белом экране, например

String[] items = {"First L Name","First L Name","First L Name"}; 

Тогда

setContentView(R.layout.main);
setListAdapter(new NewListAdapter(this));

Расширьте класс NewListAdapter с помощью любого адаптера, например ArrayAdapter, и сделайте это

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);
    }       
}

Теперь запустите свой код и увидите магию ...

0 голосов
/ 31 декабря 2011

Здесь вы можете использовать listView.addheadview и listView.addrootview edit:

<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="我的靓衣间" />  


        <Button android:id="@+id/preButton"
                android:layout_width="90dip" 
                android:layout_height="46dip"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="9dip"
                android:text="前页"
                android:layout_marginTop="1dip"
                android:background="@drawable/btn_default"
                android:textColor="#FFFFFF"

               />
     <Button android:id="@+id/midchoth"
              android:layout_width="90dip" 
              android:layout_height="46dip"
              android:layout_marginLeft="12dip"
              android:background="@drawable/btn_default"
              android:layout_marginTop="1dip"
              android:textColor="#FFFFFF"
              android:visibility="invisible"
              android:text="继续"
               />
      <Button android:id="@+id/backbu"
               android:layout_width="90dip" 
                android:layout_height="46dip"
                android:layout_marginLeft="12dip"
                 android:background="@drawable/btn_default"
                  android:layout_marginTop="1dip"
                android:textColor="#FFFFFF"
                 android:text="后页"
               />
    </LinearLayout>

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...