0

嗨,我是Android新手。是否可以在同一屏幕上添加两个ListView并行?我已经使用一个ListView并使用ListAdapter显示项目,但实际上我需要它:当它显示项目并滚动水平时,我想要第一个TextView冻结,当我滚动垂直时,它将滚动。如何并行添加两个ListViews?

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:

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

+0

试框架布局 – KOTIOS

+0

或尝试的RelativeLayout – Giant

+0

@ Android28确定我会尝试 – ibu

回答

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> 

其中2 LinearLayout的将有重量 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)); 
} 
+0

其没有工作只能显示一个列表视图 – ibu

+0

您需要将是XML代码为LiearLayout.Ok,我在我的answer.I测试它更新,它的工作原理完美。让我知道你呢? – ridoy

1

@ 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> 

仍然有任何查询,PLZ问。