【问题标题】:Layout issue on Android with FrameLayout and ScrollView带有 FrameLayout 和 ScrollView 的 Android 布局问题
【发布时间】:2012-01-01 14:51:43
【问题描述】:

我正在尝试将屏幕分成 2 个区域,左侧是 ImageView,右侧是 ScrolView。我正在以编程方式添加ImageView 和 ScrollView 的内容,因此布局的 xml 文件如下所示:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <FrameLayout
            android:id="@+id/scene_view"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="left"
            >
    </FrameLayout>
    <ScrollView
            android:layout_height="fill_parent"
            android:layout_width="@dimen/scrollmenu_width"
            android:layout_gravity="right"
            >
        <LinearLayout
                android:id="@+id/scrollmenu"
                android:layout_height="fill_parent"
                android:orientation="vertical"
                android:layout_width="fill_parent"
                >
        </LinearLayout>
    </ScrollView>
</FrameLayout>

我做错了什么?因为我将ScrollView 置于右侧,但ImageView 居中(相对于屏幕)位于屏幕左侧。图像的分辨率超过了屏幕的分辨率,所以我得到黑色 sp

【问题讨论】:

    标签: android layout scrollview android-framelayout


    【解决方案1】:

    我认为你应该使用LinearLayout 和weight 参数来解决这个问题。

    我已经编辑了您的 sn-p,让您了解应该如何使用它。

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal">
    
        <FrameLayout
            android:id="@+id/scene_view"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_gravity="left"
            android:layout_weight=1>
        </FrameLayout>
        <ScrollView
            android:layout_height="fill_parent"
            android:layout_width="0dp"
            android:layout_weight=1
            android:layout_gravity="right">
            <LinearLayout
                android:id="@+id/scrollmenu"
                android:layout_height="fill_parent"
                android:orientation="vertical"
                android:layout_width="fill_parent">
            </LinearLayout>
        </ScrollView>
    </FrameLayout>
    

    希望对你有帮助..

    【讨论】:

    • 啊,我知道这是可能的,只是我是 Android 新手,在这种情况下并没有想到。谢谢,解决方案有效,尽管这不是您在 LinearLayout 上编写权重参数的方式
    • 对不起,我很高兴能帮上忙。
    猜你喜欢
    • 2010-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-21
    • 2017-10-15
    • 1970-01-01
    • 2017-06-05
    相关资源
    最近更新 更多