Android ListView 不滚动

标签 android android-layout android-listview android-scrollview android-scroll

我有一个布局,它的起始标签(父标签是 )是

<scroll view  
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

后来我有很多图像、 TextView 、编辑文本和其他东西,最后是 ListView 。 我已经按照我的规定将 listview 的高度定义为 230dp。 问题是整个布局滚动得很好,但 ListView 中的内容没有单独滚动。这是 xml 的样子...

    <ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     > 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:orientation="vertical" >
    <TextView android:layout_width="fill_parent"
         android:layout_height="50dp"
         android:text="BISCOOT"
         android:textSize="25dp"
         android:background="@drawable/item_bg_light"
         android:textColor="@android:color/white"
         android:gravity="center"/>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" android:layout_width="fill_parent" 
     android:layout_height="200dp" android:background="#ff000000">

      <ImageSwitcher android:id="@+id/switcher1" android:layout_width="fill_parent" 
      android:layout_height="200dp"  
      android:layout_alignParentLeft="true" android:layout_alignParentRight="true" >
      </ImageSwitcher> 
        <ProgressBar
              android:id="@+id/progressBar2"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"  android:layout_centerHorizontal="true"
               />
        <ImageButton android:id="@+id/imageButton1" android:layout_width="wrap_content"
       android:layout_height="wrap_content" android:layout_alignParentRight="true" 
       android:layout_centerVertical="true" android:src="@android:drawable/ic_media_ff" /> 

        <ImageButton android:id="@+id/imageButton2" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:layout_alignParentLeft="true" 
      android:layout_alignTop="@+id/imageButton1" android:src="@android:drawable/ic_media_rew" /> 
  </RelativeLayout>
    <TextView android:layout_width="fill_parent"
         android:layout_height="30dp"
         android:text="Latest headLines"
         android:background="@drawable/item_bg_light"
         android:textColor="@android:color/white"
         android:gravity="center"/>
    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />
         <LinearLayout android:orientation="vertical"
             android:layout_width="fill_parent"            
             android:layout_height="fill_parent">
      <ListView 
        android:id="@android:id/list" 
        android:layout_width="fill_parent" 
        android:scrollbarFadeDuration="0" 
        android:scrollbarStyle="outsideOverlay" 
        android:smoothScrollbar="true" 
          android:layout_height="260dp">
     </ListView>
    </LinearLayout>



    <!-- 
    <TextView android:layout_width="fill_parent"
         android:layout_height="30dp"
         android:text="Heroin On the Rocks"
         android:background="@drawable/item_bg_light"
         android:textColor="@android:color/white"
         android:gravity="center"/>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" android:layout_width="fill_parent" 
     android:layout_height="200dp" android:background="#ff000000">

      <ImageSwitcher android:id="@+id/switcher2" android:layout_width="fill_parent" 
      android:layout_height="200dp"  
      android:layout_alignParentLeft="true" android:layout_alignParentRight="true" /> 

        <ImageButton android:id="@+id/imageButton3" android:layout_width="wrap_content"
       android:layout_height="wrap_content" android:layout_alignParentRight="true" 
       android:layout_centerVertical="true" android:src="@android:drawable/ic_media_ff" /> 

        <ImageButton android:id="@+id/imageButton4" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:layout_alignParentLeft="true" 
      android:layout_alignTop="@+id/imageButton1" android:src="@android:drawable/ic_media_rew" /> 
  </RelativeLayout>
  -->




<TextView android:layout_width="fill_parent"
         android:layout_height="30dp"
         android:text="Watch Movies"
         android:background="@drawable/item_bg_light"
         android:textColor="@android:color/white"
         android:gravity="center"/>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="100dp" android:orientation="horizontal"
    android:weightSum="6"
    >
        <ImageView 

            android:layout_height="100dp"
            android:layout_width="wrap_content" android:layout_weight="1"
           android:layout_marginLeft="2dp" android:layout_marginRight="2dp"
            android:id="@+id/watchmoviesimg1"
            />
         <ImageView android:layout_height="100dp"
            android:layout_width="wrap_content" android:layout_weight="1"
           android:layout_marginLeft="2dp" android:layout_marginRight="2dp"
            android:id="@+id/watchmoviesimg2"/>
          <ImageView android:layout_height="100dp" android:layout_weight="1"
            android:layout_width="wrap_content"
           android:layout_marginLeft="2dp" android:layout_marginRight="2dp"
            android:id="@+id/watchmoviesimg3"/>

          <ProgressBar
              android:id="@+id/progressBar3"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="center" />

           <ImageView android:layout_height="100dp" android:layout_weight="1"
            android:layout_width="wrap_content"
           android:layout_marginLeft="2dp" android:layout_marginRight="2dp"
            android:id="@+id/watchmoviesimg4"/>
            <ImageView android:layout_height="100dp" android:layout_weight="1"
            android:layout_width="wrap_content"
           android:layout_marginLeft="2dp" android:layout_marginRight="2dp"
            android:id="@+id/watchmoviesimg5"/>
             <ImageView android:layout_height="100dp" android:layout_weight="1"
            android:layout_width="wrap_content"
           android:layout_marginLeft="2dp" android:layout_marginRight="2dp"
            android:id="@+id/watchmoviesimg6"/>


    </LinearLayout>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="200dp" 
    android:orientation="vertical"
    >
              <TextView android:layout_width="fill_parent"
         android:layout_height="30dp"
         android:text="Photo Stories"
         android:background="@drawable/item_bg_light"
         android:textColor="@android:color/white"
         android:gravity="center"/>

              <ProgressBar
                  android:id="@+id/progressBar4"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center" />

               <ImageView 
                   android:id="@+id/photostoryimageview1"
                   android:layout_height="200dp" android:layout_weight="1"
            android:layout_width="fill_parent"
            />
               </LinearLayout>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="200dp" 
    android:orientation="vertical"
    >
                 <TextView android:layout_width="fill_parent"
         android:layout_height="30dp"
         android:text="Star Special"
         android:background="@drawable/item_bg_light"
         android:textColor="@android:color/white"
         android:gravity="center"/>

                 <ProgressBar
                     android:id="@+id/progressBar5"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content" 
                     android:layout_gravity="center"/>

               <ImageView 
                   android:id="@+id/starSpecialimageView1"
                   android:layout_height="200dp" android:layout_weight="1"
            android:layout_width="fill_parent"
            />
               </LinearLayout>

</LinearLayout>
</ScrollView>

最佳答案

只需从您的布局中删除 ScrollView。并且,将 LinearLayout 作为父级。并且,尝试运行您的应用程序。它将滚动列表。

因为 ListView 类实现了它自己的滚动,它只是不接收手势,因为它们都由父级 ScrollView 处理 我强烈建议您简化布局不知何故。例如,您可以将要滚动的 View 添加到 ListView 作为页眉或页脚。

看看this

更新

采用一个父布局和两个子布局。而且,在一种布局中,它应该包含 ScrollView 和您的内容。并且,在另一个布局上包含您的 ListView 试试 this他就是那样做的。

关于Android ListView 不滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12276138/

相关文章:

java - 使用 onPreferenceClick 启动 Activity

javascript - 无法通过angularjs在phonegap中显示联系人照片

java - 安卓:Epub 文件在模拟器/安卓设备中不显示图像

android - 在android- ListView 中仅找出完全可见的列表项

java - 拍摄照片并在 Android 的 ImageView 中以全尺寸显示

android - 在android中检测拨出电话

android - 如何从 SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 恢复?

Android ImageView 大小在平板电脑中没有改变

android - 通过 Intents 将 listView 行位置传递给另一个类

java - 带分隔符的自定义 ListView 变得疯狂