0

Two listviews which are showing different data in layout XML file and there is the code:

 <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/detaillistview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:clickable="false"
            android:headerDividersEnabled="false" >
        </ListView>

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/divider" />

        <ListView
            android:id="@+id/reviewlistview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:clickable="false"
            android:headerDividersEnabled="false" >
        </ListView>
    </LinearLayout>

But when the top listview is full of the screen I will never see the bottom one. Any idea to fix this? Thank you in advance!

4

4 回答 4

3

Keep the LinearLayout in a ScrollView. Thats it.

I have used the same format as shown below:

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

<TextView
    android:id="@+id/lblHeading"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:gravity="center"
    android:textColor="#ffffffff"
    android:textSize="20sp"
    android:textStyle="bold" />

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/lblBody"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:textColor="#ffffffff"
            android:textSize="18sp" />

        <EditText
            android:id="@+id/txtText"
            android:layout_width="fill_parent"
            android:layout_height="170dp"
            android:layout_weight="1"
            android:autoText="true"
            android:gravity="left"
            android:scrollbars="vertical"
            android:textSize="16sp" >

            <requestFocus />
        </EditText>

        <Button
            android:id="@+id/btnButton"
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:layout_gravity="center_horizontal"
            android:gravity="center"
            android:textSize="18dp"
            android:textStyle="bold" />

        <Button
            android:id="@+id/btnReturn"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:gravity="center"
            android:textSize="18dp"
            android:textStyle="bold" />
    </LinearLayout>
</ScrollView>
</LinearLayout>
于 2012-12-20T11:23:48.020 回答
2

if You want to show them in screen you should use weight , but you need scroll you should wrap linearlayout with ScrollView, try code below,

<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/detaillistview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="false"
            android:headerDividersEnabled="false" >

        </ListView>

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/divider" />

        <ListView
            android:id="@+id/reviewlistview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="false"
            android:headerDividersEnabled="false" >

        </ListView>
    </LinearLayout>
于 2012-12-20T11:28:22.460 回答
1

There are Two ways to show two Listview in One Layout.They are as follows

1)First if you want to show with out scrolling the view.In this case you need to mention the height of the listview.

2)In this case you need to take a ScrollView in that you need to take a layout inside that you need to declare two listviews.As follows...

<ScrollView
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/scrollView1"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:background="#ffffff"
   android:fillViewport="true" >

<RelativeLayout
   android:id="@+id/relativelayout1"
   android:layout_width="match_parent"
   android:layout_height="wrap_content" >

<ListView
   android:id="@+id/listView1"
   android:layout_width="match_parent"
   android:layout_height="wrap_content" />
<ImageView
   android:id="@+id/imageView"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:src="@drawable/divider" />
<ListView
   android:id="@+id/listView2"
   android:layout_width="match_parent"
   android:layout_height="wrap_content" />
</RelativeLayout>
</ScrollView>
于 2012-12-21T09:05:35.130 回答
1
public class SeparatedListAdapter extends BaseAdapter
{

public final Map<String, Adapter> sections = new LinkedHashMap<String, Adapter>();
public final ArrayAdapter<String> headers;
public final static int TYPE_SECTION_HEADER = 0;

public SeparatedListAdapter(Context context)
{
    headers = new ArrayAdapter<String>(context, R.layout.list_header);
}

public void addSection(String section, Adapter adapter)
{
    this.headers.add(section);
    this.sections.put(section, adapter);
}

public Object getItem(int position)
{
    for (Object section : this.sections.keySet())
    {
        Adapter adapter = sections.get(section);
        int size = adapter.getCount() + 1;

        // check if position inside this section
        if (position == 0)
            return section;
        if (position < size)
            return adapter.getItem(position - 1);

        // otherwise jump into next section
        position -= size;
    }
    return null;
}

public int getCount()
{
    // total together all sections, plus one for each section header
    int total = 0;
    for (Adapter adapter : this.sections.values())
        total += adapter.getCount() + 1;
    return total;
}

public int getViewTypeCount()
{
    // assume that headers count as one, then total all sections
    int total = 1;
    for (Adapter adapter : this.sections.values())
        total += adapter.getViewTypeCount();
    return total;
}

public int getItemViewType(int position)
{
    int type = 1;
    for (Object section : this.sections.keySet())
    {
        Adapter adapter = sections.get(section);
        int size = adapter.getCount() + 1;

        // check if position inside this section
        if (position == 0)
            return TYPE_SECTION_HEADER;
        if (position < size)
            return type + adapter.getItemViewType(position - 1);

        // otherwise jump into next section
        position -= size;
        type += adapter.getViewTypeCount();
    }
    return -1;
}

public boolean areAllItemsSelectable()
{
    return false;
}

public boolean isEnabled(int position)
{
    return (getItemViewType(position) != TYPE_SECTION_HEADER);
}

@Override
public View getView(int position, View convertView, ViewGroup parent)
{

    int sectionnum = 0;
    for (Object section : this.sections.keySet())
    {
        Adapter adapter = sections.get(section);
        int size = adapter.getCount() + 1;

        // check if position inside this section
        if (position == 0)
            return headers.getView(sectionnum, convertView, parent);
        if (position < size)
            return adapter.getView(position - 1, convertView, parent);

        // otherwise jump into next section
        position -= size;
        sectionnum++;
    }
    return null;
}

@Override
public long getItemId(int position)
{
    return position;
}

}

I use this to put two different kinds of data in one listview using sections!

于 2012-12-24T05:07:47.243 回答