在 FrameLayout 上滚动 2 个 ScrollView 时出现问题

发布于 2024-11-10 13:48:26 字数 4096 浏览 6 评论 0原文

我有一个 FrameLayout ,它有一个 ScrollView 作为唯一的孩子。在运行时,我会膨胀一个 RelativeLayout,其中有一个 ScrollView 并将其添加到 FrameLayout (此子视图现在与之前的 ScrollView 重叠)。我已使用 LockableScrollView 作为 FrameLayout 的第一个子级,因此,我可以通过设置来禁用它的滚动scrollable 属性设置为 false,在新子项添加到 FrameLayout 后,focusable 和 clickable 属性也设置为 false。但我仍然无法滚动新的 ScrollView。有什么指点吗?

以下是根布局。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/frame"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <RelativeLayout
        android:id="@+id/relative_layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/questions_bg">

        <ImageView
            android:id="@+id/questions_header"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:scaleType="fitXY"
            android:src="@drawable/header_bg" />

        <com.package.ui.LockableScrollView
            android:id="@+id/question_scrollview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_below="@id/questions_header"
            android:scrollbarAlwaysDrawVerticalTrack="true"
            android:scrollbarStyle="insideOverlay"
            android:scrollbarFadeDuration="0"
            android:fillViewport="true">

            <!-- Some more views -->

        </com.package.ui.LockableScrollView>    
    </RelativeLayout>
</FrameLayout>

以下是在运行时膨胀并添加到 FrameLayout 的子布局。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|center_horizontal"
    android:layout_marginBottom="20dp">

    <ImageView
        android:id="@+id/q_map_header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:src="@drawable/en_question_map_header" />

    <ImageView
        android:id="@+id/q_map_bg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/q_map_header"
        android:src="@drawable/question_map_content" />

    <ImageView
        android:id="@+id/q_map_footer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/q_map_bg"
        android:paddingBottom="50dp"
        android:src="@drawable/en_question_map_footer" />

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/q_map_header"
        android:layout_above="@id/q_map_footer"
        android:layout_marginLeft="28dp"
        android:layout_marginRight="30dp"
        android:layout_marginTop="14dp"
        android:layout_marginBottom="14dp"
        android:layout_alignLeft="@id/q_map_header"
        android:layout_alignRight="@id/q_map_header"
        android:fillViewport="true" >

        <GridView
            android:id="@+id/q_map_grid"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:numColumns="5"
            android:verticalSpacing="8dp"
            android:horizontalSpacing="8dp"
            android:stretchMode="columnWidth"
            android:gravity="center_horizontal" />
    </ScrollView>
</RelativeLayout>

I have a FrameLayout which has a ScrollView as the only child. During runtime I inflate a RelativeLayout which has a ScrollView within and add it to the FrameLayout (This child view now overlaps the previous ScrollView). I have used a LockableScrollView as the first child of the FrameLayout so, I can disable it's scrolling by setting the scrollable property to false, the focusable and clickable properties are also set to false after the new child is added to the FrameLayout. But still I'm unable to scroll the new ScrollView. Any pointers?

The following is the Root layout.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/frame"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <RelativeLayout
        android:id="@+id/relative_layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/questions_bg">

        <ImageView
            android:id="@+id/questions_header"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:scaleType="fitXY"
            android:src="@drawable/header_bg" />

        <com.package.ui.LockableScrollView
            android:id="@+id/question_scrollview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_below="@id/questions_header"
            android:scrollbarAlwaysDrawVerticalTrack="true"
            android:scrollbarStyle="insideOverlay"
            android:scrollbarFadeDuration="0"
            android:fillViewport="true">

            <!-- Some more views -->

        </com.package.ui.LockableScrollView>    
    </RelativeLayout>
</FrameLayout>

The following is the child layout that is inflated during runtime and added to the FrameLayout.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|center_horizontal"
    android:layout_marginBottom="20dp">

    <ImageView
        android:id="@+id/q_map_header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:src="@drawable/en_question_map_header" />

    <ImageView
        android:id="@+id/q_map_bg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/q_map_header"
        android:src="@drawable/question_map_content" />

    <ImageView
        android:id="@+id/q_map_footer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/q_map_bg"
        android:paddingBottom="50dp"
        android:src="@drawable/en_question_map_footer" />

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/q_map_header"
        android:layout_above="@id/q_map_footer"
        android:layout_marginLeft="28dp"
        android:layout_marginRight="30dp"
        android:layout_marginTop="14dp"
        android:layout_marginBottom="14dp"
        android:layout_alignLeft="@id/q_map_header"
        android:layout_alignRight="@id/q_map_header"
        android:fillViewport="true" >

        <GridView
            android:id="@+id/q_map_grid"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:numColumns="5"
            android:verticalSpacing="8dp"
            android:horizontalSpacing="8dp"
            android:stretchMode="columnWidth"
            android:gravity="center_horizontal" />
    </ScrollView>
</RelativeLayout>

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

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

发布评论

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

评论(1

哆啦不做梦 2024-11-17 13:48:26

您不能将一个可滚动容器(此处为 GridView)放置在另一个可滚动容器(此处为 ScrollView)中。

You can't place a scrollable container (Here GridView) within another scrollable container (Here ScrollView).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文