Layout issue on Android with FrameLayout and ScrollView

时光总嘲笑我的痴心妄想 提交于 2020-01-05 08:43:31

问题


I'm trying to split the screen in 2 areas, to the left an ImageView and to the right a ScrolView. I'm adding the ImageView and the content of the ScrollView programatically, so the xml file of the layout looks like this:

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

What am I doing wrong? because I'm getting the ScrollView to the right, but the ImageView centered (relative to the screen) placed on the left of the screen. The resolution of the image exceeds the screen's resolution so I get black sp


回答1:


I think you should make use of the LinearLayout and the weight parameter to solve this problem.

I have edited your snippet to give you an idea of how you should use it.

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

I hope it helps..



来源:https://stackoverflow.com/questions/8693648/layout-issue-on-android-with-framelayout-and-scrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!