gpt4 book ai didi

Android ListView 不滚动

转载 作者:太空狗 更新时间:2023-10-29 15:33:46 25 4
gpt4 key购买 nike

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com