【问题标题】:Can not scroll my LinearLayout无法滚动我的 LinearLayout
【发布时间】:2018-11-02 04:14:28
【问题描述】:

我有一个布局,并尝试使其内部的组件可滚动,它应该能够滚动 listView 和 Pdf-View 并且它应该能够同时滚动 ListView 和 Pdf-View

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        tools:context=".uiFragments.HerstellerunterlagenInstandhalterFragment">

    <ScrollView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:background="@drawable/back"
                android:layout_gravity="center_horizontal"
                android:orientation="vertical">

                <ListView
                    android:id="@+id/listview_anlagenuebersicht_instandhalter"
                    android:layout_marginTop="1dp"
                    android:layout_marginBottom="1dp"
                    android:layout_marginLeft="1dp"
                    android:layout_marginRight="1dp"
                    android:listSelector="@drawable/bkg"
                    android:background="@android:color/white"
                    android:layout_height="70dp"
                    android:layout_width="650dp"/>
            </LinearLayout>

            <com.github.barteksc.pdfviewer.PDFView
                android:id="@+id/pdfView_anlage"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="100dp"/>

         </LinearLayout>
    </ScrollView>
</FrameLayout> 

我想“滚动”我的 PDF 查看器列表视图,一起,但它不起作用,我只能滚动我的 listView 和 @987654324 @分别

【问题讨论】:

  • 你必须使用 - android.support.v4.widget.NestedScrollView 进行滚动。
  • 您可以使用NonscrollableListview。并使用nestedscrollview 而不是scrollview

标签: android android-layout android-studio android-fragments scrollview


【解决方案1】:

您可以使用android:isScrollContainer="true"。它将表明该视图是其窗口中的一组可滚动容器之一。更多信息请阅读https://developer.android.com/reference/android/view/View

【讨论】:

    【解决方案2】:

    因为列表视图有自己的滚动视图,所以你不能将它添加到另一个滚动视图中,所以你必须单独使用它们

    【讨论】:

      【解决方案3】:
      1. 您不应该将 ListView 放在 ScrollView 中,因为 ListView 类实现了它自己的滚动,它只是没有 接收手势,因为它们都由父母处理 滚动视图。我强烈建议您简化布局 不知何故。例如,您可以添加要滚动到的视图 ListView 作为页眉或页脚。

            UPDATE:
        
            Starting from API Level 21 (Lollipop) nested scroll containers are officially supported by Android SDK. There're a bunch
        

        View 和 ViewGroup 类中提供此功能的方法 功能。要在 Lollipop 上进行嵌套滚动,您 必须通过添加为子滚动视图启用它 android:nestedScrollingEnabled="true" 到它的 XML 声明或通过 显式调用 setNestedScrollingEnabled(true)。

            If you want to make nested scrolling work on pre-Lollipop devices, which you probably do, you have to use corresponding
        

        来自支持库的实用程序类。首先你必须更换 你 ScrollView 和 NestedScrollView。后者同时实现 NestedScrollingParent 和 NestedScrollingChild 所以它可以用作 父或子滚动容器。

            But ListView doesn't support nested scrolling, therefore you need to subclass it and implement NestedScrollingChild. Fortunately,
        

        Support 库提供了 NestedScrollingChildHelper 类,所以 你只需要创建这个类的一个实例并调用它 视图类的相应方法中的方法。

        ** 更多详情:ListView inside ScrollView is not scrolling on Android

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-11-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多