1

在应用程序的开发阶段,我对一个地方感到震惊,滚动......

在应用程序中,我有两个ListView项目用于列出一些不同的数据。我的列表可以显示 n 个项目。如果我有一个单一的ListView手段,我将使用'ScrollView'全屏..

在这我该如何实现呢?

我的代码是,..

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

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        android:padding="30dp" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="Average"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/average"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Medium Text"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="Maximum"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/maximum"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Medium Text"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="Minimum"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/minmum"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Medium Text"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </LinearLayout>
    </LinearLayout>

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="437dp"
            android:layout_weight="1"
            android:orientation="vertical"
            android:padding="30dp" >

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="Top Students List"
                android:padding="10dp"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <ListView
                android:id="@+id/list1"
                android:layout_width="wrap_content"
                android:layout_height="302dp"
                android:layout_gravity="center" >
            </ListView>
        </LinearLayout>
    </ScrollView>

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:orientation="vertical"
            android:padding="30dp" >

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="Bottom Students List"
                android:textAppearance="?android:attr/textAppearanceMedium" 
                android:padding="10dp"/>

            <ListView
                android:id="@+id/list2"
                android:layout_width="wrap_content"
                android:layout_height="302dp"
                android:layout_gravity="center" >
            </ListView>
        </LinearLayout>
    </ScrollView>
</LinearLayout>
</ScrollView>

在这里,我尝试了“ListView”中的滚动条,...

 <ListView
      android:id="@+id/list1"
      android:layout_width="wrap_content"
      android:layout_height="302dp"
      android:layout_gravity="center"
      android:scrollbars="vertical" >
 </ListView>

它在我的系统中工作,在开发时,但在平板电脑中我无法滚动它,..因为在我的电脑中我使用鼠标的滚动器来执行该活动,但在平板电脑中没有选项......

给我关于向下滚动我的“ListView”的建议,它只需要显示 4 个列表项一次。其他项目将在执行滚动功能时显示...

4

1 回答 1

1

我只是ScrollView从 XML 文件中删除 ScrollView。因为ListView默认具有向下滚动的特征..

所以我的新代码是,..

<?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="fill_parent"
android:orientation="vertical" >
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:orientation="vertical"
    android:padding="30dp" >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal" >
        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="Average"
           android:textAppearance="?android:attr/textAppearanceMedium" />
        <TextView
            android:id="@+id/average"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Medium Text"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal" >
        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="Maximum"
            android:textAppearance="?android:attr/textAppearanceMedium" />
        <TextView
            android:id="@+id/maximum"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Medium Text"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal" >
        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="Minimum"
            android:textAppearance="?android:attr/textAppearanceMedium" />
        <TextView
            android:id="@+id/minmum"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Medium Text"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    </LinearLayout>
</LinearLayout>
<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="437dp"
        android:layout_weight="1"
        android:orientation="vertical"
        android:padding="30dp" >

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Top Students List"
            android:padding="10dp"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <ListView
            android:id="@+id/list1"
            android:layout_width="wrap_content"
            android:layout_height="302dp"
            android:layout_gravity="center" >
        </ListView>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        android:padding="30dp" >

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Bottom Students List"
            android:textAppearance="?android:attr/textAppearanceMedium" 
            android:padding="10dp"/>

        <ListView
            android:id="@+id/list2"
            android:layout_width="wrap_content"
            android:layout_height="302dp"
            android:layout_gravity="center" >
        </ListView>
    </LinearLayout>
</LinearLayout>

及其工作...

于 2012-12-22T10:38:21.190 回答