Search code examples
javaandroidlayoutandroid-framelayout

Android framelayouts side by side


I would like to put two framelayouts side by side horizontally. My layout.xml is:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.agodevs.vrcamera.MainActivity" >
<FrameLayout android:id="@+id/camera_previewl" android:layout_width="fill_parent"  android:layout_height="wrap_content"></FrameLayout>
<FrameLayout android:id="@+id/camera_previewr" android:layout_width="fill_parent" android:layout_height="wrap_content"></FrameLayout>
</RelativeLayout>

I can only see one framelayout horizontally. What did I do wrong?


Solution

  • Use this:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    tools:context="com.agodevs.vrcamera.MainActivity" >
    
    <FrameLayout
        android:id="@+id/camera_previewl"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#ff0000" >
    </FrameLayout>
    
    <FrameLayout
        android:id="@+id/camera_previewr"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#000" >
    </FrameLayout>
    
    </LinearLayout>