如何将两个ListView滚动为一个?

时间:2015-04-30 07:47:09

标签: xamarin xamarin.android

我有两个列表视图并排,但我想将两个列表视图滚动为一个如何做到这一点?

尝试使用OnClickListener,但它似乎不起作用?

1 个答案:

答案 0 :(得分:0)

我认为最好的方法是将每个列表视图放在LinearLayout和指定的宽度内。这可以并排显示列表视图。仔细查看填充其父级的列表视图,布局不会像您期望的那样显示。 ListView可能会绕过父级的width参数。 之后,您需要将这些LinearLayouts放在Scrollview上,您需要设置fillViewport。您可以从here

获取有关fillViewport的详细信息
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical" >

   <ScrollView
     android:id="@+id/scrollView1"
     android:background="#000000"
     android:layout_width="match_parent"
     android:fillViewport="true" <!-- here -->
     android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/linear1"
        android:background="#FF0000"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:background="#00FF00"
            android:id="@+id/linear2"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:orientation="vertical" >
           <ListView
            android:id="@+id/ListView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:divider="@drawable/settingsMenuBorder"
            android:scrollbars="none"
            android:layout_marginTop="30dp"
            android:textSize="20sp" />
        </LinearLayout>

        <LinearLayout
            android:background="#0000FF"
            android:id="@+id/linear3"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:orientation="vertical" >
           <ListView
            android:id="@+id/ListView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:divider="@drawable/settingsMenuBorder"
            android:scrollbars="none"
            android:layout_marginTop="30dp"
            android:textSize="20sp" />
        </LinearLayout>

    </LinearLayout>
 </ScrollView>
</RelativeLayout>