Android 是否在滚动视图中嵌套framelayout?

Android 是否在滚动视图中嵌套framelayout?,android,scrollview,android-framelayout,Android,Scrollview,Android Framelayout,我有一个问题,我不知道最好的方式去做它。我需要有一个滚动视图内的所有小部件 下面是布局,我使用了framelayout,因为我需要重叠一组图像。但是,整个framelayout不能在滚动视图中。但我需要滚动整个面板。用黄色箭头标记的零件显示框架布局 我看了这条线,但这不是我想要的 这是xml,如果有人能提供线索,我非常感谢。 谢谢 我不确定我是否完全理解了你的问题,但从我的理解来看: 你的目标 您希望在ScrollView中具有FrameLayout ScrollView中的所有内容都必须

我有一个问题,我不知道最好的方式去做它。我需要有一个滚动视图内的所有小部件

下面是布局,我使用了framelayout,因为我需要重叠一组图像。但是,整个framelayout不能在滚动视图中。但我需要滚动整个面板。用黄色箭头标记的零件显示框架布局

我看了这条线,但这不是我想要的

这是xml,如果有人能提供线索,我非常感谢。 谢谢


我不确定我是否完全理解了你的问题,但从我的理解来看:

你的目标

  • 您希望在ScrollView中具有FrameLayout
  • ScrollView中的所有内容都必须滚动,也就是说,屏幕中您在图片中发布的所有内容都必须滚动
通过查看您的代码,我猜您正在将FrameLayout和LinearLayout作为ScrollView的子对象。ScrollView只能有一个直接子级。发件人:

ScrollView是一个框架布局,这意味着您应该在其中放置一个子元素,其中包含要滚动的全部内容;此子对象本身可能是具有复杂对象层次结构的布局管理器。通常使用的子项是垂直方向的线性布局,表示用户可以滚动的顶级项的垂直数组

解决方案

因此,在本例中,您希望将该框架布局和线性布局包装到另一个视图组(可以是线性布局)下,如下所示:

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
        <!--This LinearLayout wraps your frame and linear layouts so that they both stay into scrollview and are scrollable-->
        <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
            <ImageView
                android:id="@+id/image_background"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:background="@drawable/follow_add" />
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="100dp"
                android:gravity="center|bottom"
                android:orientation="horizontal">
                <ImageView
                    android:id="@+id/image_icon"
                    android:layout_width="120dp"
                    android:layout_height="120dp"
                    android:background="@drawable/feed_active" />
            </LinearLayout>

            <ImageView
                android:id="@+id/dismiss"
                android:layout_gravity="left"
                android:layout_margin="5dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/close_messages_modal" />
            <ImageView
                android:id="@+id/follow"
                android:layout_gravity="right"
                android:layout_margin="5dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/follow_add" />
        </FrameLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <TextView
                android:id="@+id/textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="10dp"
                android:text="Layout above needs to scroll"
                android:textColor="@color/half_dark_text_color"
                android:textSize="28sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:layout_marginTop="20dp"
                android:text="text1\ntext1\ntext1\ntext1\ntext1\ntext1\ntext1\ntext1\ntext1"
                android:textColor="@color/half_dark_text_color"
                android:textSize="18sp"
                android:textStyle="bold" />
            <ImageView
                android:id="@+id/id3"
                android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                android:background="@drawable/close_messages_modal" />
            <ImageView
                android:id="@+id/share"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:background="@drawable/close_messages_modal" />
        </LinearLayout>
        </LinearLayout>
    </ScrollView>

这样,ScrollView只有一个直接子级,并且其中的所有内容都将滚动

这应该足以实现你想要的。让我知道这是否是你真正想要的,至少这是我从你的帖子中理解的

干杯

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
        <!--This LinearLayout wraps your frame and linear layouts so that they both stay into scrollview and are scrollable-->
        <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
            <ImageView
                android:id="@+id/image_background"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:background="@drawable/follow_add" />
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="100dp"
                android:gravity="center|bottom"
                android:orientation="horizontal">
                <ImageView
                    android:id="@+id/image_icon"
                    android:layout_width="120dp"
                    android:layout_height="120dp"
                    android:background="@drawable/feed_active" />
            </LinearLayout>

            <ImageView
                android:id="@+id/dismiss"
                android:layout_gravity="left"
                android:layout_margin="5dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/close_messages_modal" />
            <ImageView
                android:id="@+id/follow"
                android:layout_gravity="right"
                android:layout_margin="5dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/follow_add" />
        </FrameLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <TextView
                android:id="@+id/textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="10dp"
                android:text="Layout above needs to scroll"
                android:textColor="@color/half_dark_text_color"
                android:textSize="28sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:layout_marginTop="20dp"
                android:text="text1\ntext1\ntext1\ntext1\ntext1\ntext1\ntext1\ntext1\ntext1"
                android:textColor="@color/half_dark_text_color"
                android:textSize="18sp"
                android:textStyle="bold" />
            <ImageView
                android:id="@+id/id3"
                android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                android:background="@drawable/close_messages_modal" />
            <ImageView
                android:id="@+id/share"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:background="@drawable/close_messages_modal" />
        </LinearLayout>
        </LinearLayout>
    </ScrollView>