Android 如何使用ScrollView和线性布局仅使部分布局可滚动?

Android 如何使用ScrollView和线性布局仅使部分布局可滚动?,android,android-linearlayout,android-scrollview,scrollable,Android,Android Linearlayout,Android Scrollview,Scrollable,我有一个layout.xml,它分为两部分,其中一部分包括垂直填充的字段,另一部分(初始)包括3个CardView,这些CardView将用于填充imageView(稍后),但是,当尝试仅让CardView水平滚动时,什么都不会发生,唯一发生的事情是,整个布局是垂直滚动的,但没有任何CardView是水平滚动的 .xml存档的代码: 您必须添加另一个布局,以便放置滚动视图。。。但是XML的结构并不好。首先,您必须有两个线性布局,第一个用于带CardView的水平ScrolView,第二个用于带

我有一个layout.xml,它分为两部分,其中一部分包括垂直填充的字段,另一部分(初始)包括3个CardView,这些CardView将用于填充imageView(稍后),但是,当尝试仅让CardView水平滚动时,什么都不会发生,唯一发生的事情是,整个布局是垂直滚动的,但没有任何CardView是水平滚动的

.xml存档的代码:



您必须添加另一个布局,以便放置滚动视图。。。但是XML的结构并不好。首先,您必须有两个线性布局,第一个用于带CardView的水平ScrolView,第二个用于带其余XML的垂直ScrolView。。。如果你需要更多的帮助,请告诉我

您必须添加另一个布局,以便放置滚动视图。。。但是XML的结构并不好。首先,您必须有两个线性布局,第一个用于带CardView的水平ScrolView,第二个用于带其余XML的垂直ScrolView。。。如果你需要更多的帮助,请告诉我

另一个ScrollView中ScrollView的行为是不可预测的,您应该尝试NestedScrollingParent2和NestedScrollingChild2。

另一个ScrollView中ScrollView的行为是不可预测的,您应该尝试NestedScrollingParent2和NestedScrollingChild2。

看看如何做到这一点。。。忘记FrameLayout,使用线性布局作为主布局

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

    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <GridLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:background="@drawable/avli_horse"/>
            <ImageView
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:background="@drawable/bar"/>
            <ImageView
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:background="@drawable/kitchen"/>
            <ImageView
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:background="@drawable/avli_logo"/>

        </GridLayout>

    </HorizontalScrollView>

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:orientation="vertical"
    android:layout_weight="3">



<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <ImageView
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:background="@drawable/avli_horse" />

        <ImageView
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:background="@drawable/bar" />

        <ImageView
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:background="@drawable/kitchen" />

        <ImageView
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:background="@drawable/avli_logo" />


    </LinearLayout>

</ScrollView>

</LinearLayout>

看看你是如何做到的。。。忘记FrameLayout,使用线性布局作为主布局

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

    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <GridLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:background="@drawable/avli_horse"/>
            <ImageView
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:background="@drawable/bar"/>
            <ImageView
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:background="@drawable/kitchen"/>
            <ImageView
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:background="@drawable/avli_logo"/>

        </GridLayout>

    </HorizontalScrollView>

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:orientation="vertical"
    android:layout_weight="3">



<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <ImageView
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:background="@drawable/avli_horse" />

        <ImageView
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:background="@drawable/bar" />

        <ImageView
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:background="@drawable/kitchen" />

        <ImageView
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:background="@drawable/avli_logo" />


    </LinearLayout>

</ScrollView>

</LinearLayout>


这些示例是外部库?这些示例是外部库?那么我的布局应该以.xml开头吗?亲戚?每当我使用ScrolView时,我只使用FrameLayout。所以,我必须将水平和垂直滚动分隔为2个框架布局?@lukecross,看看我刚才发布的内容。。。因此,主布局使用LinearLayout,然后尝试按照我发布的代码进行操作。很好,luckso我的布局应该从.xml开始?亲戚?每当我使用ScrolView时,我只使用FrameLayout。所以,我必须将水平和垂直滚动分隔为2个框架布局?@lukecross,看看我刚才发布的内容。。。因此,主布局使用LinearLayout,然后尝试按照我发布的代码进行操作。幸运的是,我不知道水平滚动视图,我会测试并选择你的答案,在.xml之后,谁是最重要的布局(顶部)和覆盖整个代码的布局?包含属性xmlns:android=“”xmlns:tools=“”xmlns:app=“”的那个,我用“水平滚动视图”得到的,非常有用THANKS@lukecross“在您的.xml中,谁是最重要的布局(顶部)”,这是主要的线性布局。我没有在这里添加它,但这就是我提到它的原因…谢谢,我不知道水平滚动视图,我将测试并选择您的答案,在.xml之后。在您的.xml中,谁是最重要(顶部)的布局,并且涵盖了整个代码?包含属性xmlns:android=“”xmlns:tools=“”xmlns:app=“”的那个,我用“水平滚动视图”得到的,非常有用THANKS@lukecross“在您的.xml中,谁是最重要的布局(顶部)”,这是主要的线性布局。我没有加在这里,但这就是为什么我提到它。。。