使用FrameLayout和ScrollView在Android上进行布局问题

时间:2012-01-01 14:51:43

标签: android layout scrollview android-framelayout

我正在尝试将屏幕拆分为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

1 个答案:

答案 0 :(得分:2)

我认为您应该使用LinearLayoutweight参数来解决此问题。

我已编辑了您的代码段,让您了解应如何使用它。

<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>

我希望它有所帮助..