在滚动视图中使用列表视图

发布于 2025-01-04 11:31:00 字数 267 浏览 2 评论 0原文

在我的项目中,我使用了setcontentview(R.layout.first).here。在画廊中,我正在显示 second.xml。在 second.xml 中,我有一个 listview.when。我正在尝试滚动这些 listviewitems 总屏幕滚动,但它滚动不正确。因为外面我们用的是scrollview。当我删除外部滚动视图时,我们看不到列表视图的底部。如何解决这个问题?

In my project I used setcontentview(R.layout.first).here. In a gallery I am displaying second.xml. In second.xml I have one listview.when. I am trying to scroll these listviewitems total screen scrolling, but it is not scrolling properly. Because outside we used scrollview. When I delete outside scrollview we cannot see the bottom of listview. How to resolve this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

自由如风 2025-01-11 11:31:00

使用 ListView标题页脚如果你想放一些仅在 ListView 末尾/开头的项目。

观看视频(从 42:40 开始),非常有用。

Use ListView's headers and footers if you want to put some items only at the end/beginning of the ListView.

Watch this video beginning from 42:40 it's really useful.

小霸王臭丫头 2025-01-11 11:31:00

一旦列表视图超过其父级高度或 ListViews 最大高度,它将自动滚动

A list view will scroll automatically once it goes past its parents height or the ListViews maximum height

凶凌 2025-01-11 11:31:00

如果您将 ListView/任何可滚动视图放入滚动视图中,它将无法正常工作,因为当您触摸屏幕时,触摸的主要焦点是父视图(scrollView)而不是子视图(ListView)。

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

 <ListView android:layout_height="match_parent" android:id="@+id/all_workouts_list" 
    android:cacheColorHint="#ffffffff" 
    android:layout_width="match_parent" 
   android:layout_above="@+id/add_workout_all_workout_list"></ListView>

<Button android:layout_width="wrap_content"      
 android:id="@+id/add_workout_all_workout_list" android:layout_height="wrap_content" 
 android:text="Add Workout" android:layout_alignParentBottom="true"  
 android:layout_alignParentLeft="true"></Button>

</RelativeLayout>  

If you put your ListView/any scrollable View inside the scrollView it will not work properly because when you touch the screen ,main focus of your touch is on parent view(scrollView ) not the child View (ListView).

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

 <ListView android:layout_height="match_parent" android:id="@+id/all_workouts_list" 
    android:cacheColorHint="#ffffffff" 
    android:layout_width="match_parent" 
   android:layout_above="@+id/add_workout_all_workout_list"></ListView>

<Button android:layout_width="wrap_content"      
 android:id="@+id/add_workout_all_workout_list" android:layout_height="wrap_content" 
 android:text="Add Workout" android:layout_alignParentBottom="true"  
 android:layout_alignParentLeft="true"></Button>

</RelativeLayout>  
稀香 2025-01-11 11:31:00

ScrollView 中的 ListView 是不可能的。

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

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <!-- here the picture info -->
    </LinearLayout>
</LinearLayout>

ListView inside ScrollView is not possible.

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

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <!-- here the picture info -->
    </LinearLayout>
</LinearLayout>

撧情箌佬 2025-01-11 11:31:00

我没有任何现成的示例,

所以按照您在评论中的要求编写了这样的原始代码,

        ListView lv = (ListView) findViewById(R.id.listView);
        LinearLayout ll = new LinearLayout(this);
        ll.setLayoutParams(new LinearLayout.LayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)));
        Button btn = new Button(this);
        ll.addView(btn);
        lv.addFooterView(ll, null, true);

I have no any ready example with me,

So written a raw code like this as you asked in comment,

        ListView lv = (ListView) findViewById(R.id.listView);
        LinearLayout ll = new LinearLayout(this);
        ll.setLayoutParams(new LinearLayout.LayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)));
        Button btn = new Button(this);
        ll.addView(btn);
        lv.addFooterView(ll, null, true);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文