0

你好,我是安卓新手。ListView是否可以在同一个屏幕上添加两个并行?我已经使用了一个ListView并使用 显示项目ListAdapter,但实际上我需要它:当它显示项目并水平滚动时,我希望第一个TextView冻结,当我垂直滚动时,它会滚动。

xml文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="horizontal">
<!-- Main ListView 
     Always give id value as list(@android:id/list)
-->


<HorizontalScrollView
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"

        android:id="@+id/horizontalScrollView">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:background="#ffffff"
                  android:orientation="vertical">


        <TableRow
                android:id="@+id/tableRow1"
                android:scrollbarAlwaysDrawHorizontalTrack="true"
                android:layout_height="wrap_content"
                android:layout_width="match_parent">

            <TextView
                    android:id="@+id/TextView2"
                    android:text="GRPName"

                    android:background="#A513FF"

                    android:textColor="#000000"
                    android:layout_width="150dp"
                    android:padding="3dip"
                    />
            <TextView
                    android:id="@+id/TextView3" android:text="QTY"
                    android:background="#A513FF"
                    android:textColor="#000000"
                    android:layout_width="60dp"
                    android:gravity="right"

                    android:padding="3dip" />
            <TextView
                    android:id="@+id/TextView4" android:text="BUD"
                    android:background="#A513FF"
                    android:textColor="#000000"
                    android:layout_width="60dp"
                    android:gravity="right"
                    android:padding="3dip" />
            <TextView
                    android:id="@+id/TextView5" android:text="STK"
                    android:background="#A513FF"
                    android:textColor="#000000"
                    android:layout_width="60dp"
                    android:gravity="right"
                    android:padding="3dip" />
            <TextView
                    android:id="@+id/TextView2" android:text="DIF"
                    android:background="#A513FF"
                    android:gravity="right"

                    android:textColor="#000000"
                    android:layout_width="60dp"
                    android:padding="3dip"
                    />
            <TextView
                    android:id="@+id/TextView3" android:text="DIF%"
                    android:background="#A513FF"
                    android:textColor="#000000"
                    android:layout_width="60dp"
                    android:gravity="right"

                    android:padding="3dip" />


        </TableRow>
        <ListView
                android:id="@android:id/list"
                android:smoothScrollbar="true"
                android:layout_width="fill_parent"
                android:layout_weight="1"

                android:layout_height="fill_parent"/>

    </LinearLayout>


</HorizontalScrollView>

列表适配器:

ListAdapter adapter = new SimpleAdapter(this, contactList,
            R.layout.list_item,
            new String[] {  TAG_GRPNAME, TAG_QNT, TAG_BUDGET, TAG_STOCK, TAG_DIFF, TAG_DIFF_P, },
            new int[] {
                     R.id.l2, R.id.l3, R.id.l4, R.id.l5, R.id.l6, R.id.l7});
                      setListAdapter(adapter);
                      ListView lv = getListView();
                      }

我想冻结TAG_GRPNAMER.id.l2

4

2 回答 2

2

尝试这样的事情:
main.xml

<?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" >

        <LinearLayout android:layout_weight="1" 
                    android:layout_height="fill_parent" 
                    android:layout_width="fill_parent">

                <ListView   android:id="@+id/listview1" 
                            android:layout_height="fill_parent" 
                            android:layout_width="fill_parent">

                </ListView>
    </LinearLayout>

<LinearLayout android:layout_weight="1" 
                android:layout_height="fill_parent" 
                android:layout_width="fill_parent">

            <ListView   android:id="@+id/listview2" 
                        android:layout_height="fill_parent" 
                        android:layout_width="fill_parent">

            </ListView>
</LinearLayout>

</LinearLayout>

其中 2LinearLayout权重为1。
后面的代码

ListView ls1,ls2;
String colors[] = {"Red","Blue","White","Yellow","Black", "Green","Purple","Orange","Grey"};
private String phones[] = {"Android", "Blackberry", "iPhone","Windows Phone"};

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ls1 = (ListView) findViewById (R.id.listview1);
    ls2 = (ListView) findViewById (R.id.listview2);

    ls1.setAdapter(new ArrayAdapter<String> (this, android.R.layout.simple_list_item_1, colors));
    ls2.setAdapter(new ArrayAdapter<String> (this, android.R.layout.simple_list_item_1, phones));
 }
于 2013-07-12T06:31:08.963 回答
0

@ridoy 的代码稍作改动就在这里,愿你的工作完成......!

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView
        android:id="@+id/list1"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight=".50" >
    </ListView>

    <ListView
        android:id="@+id/list2"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight=".50" >
    </ListView>

</LinearLayout>

仍然有任何疑问,请询问。

于 2013-07-12T07:26:40.760 回答