2014-08-28 137 views
0

我想將兩個框架佈局並排放置。我的layout.xml是:Android框架並排佈局

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

我只能看到一個framelayout水平。我做錯了什麼?

回答

3

使用此:

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

打我到它。雖然我個人更喜歡用總和爲1的權重來閱讀它,並且因此給它們每個值0.5。實際上,這達到了相同的目標,因爲沒有提供weightSum。 – Daneo 2014-08-28 09:47:40

+0

不錯:) :) – GrIsHu 2014-08-28 09:48:51

+0

這取決於我們如何管理體重。我在腦海中保持着1:10的比例 – Piyush 2014-08-28 09:48:55

0

你有2 FrameLayouts,但你沒有指定自己的位置。您可以在camera_previewr上使用android:layout_toRightOf屬性,並指向camera_previewl作爲定位點。但RelativeLayout不需要在這裏,如果你只是想水平放置2 Views,使用LinearLayout作爲根容器,而不是android:orientation="horizontal"

+0

請注意,默認的方向**是**水平的,所以不需要指定它,至少在這種情況下不需要。 – Daneo 2014-08-28 09:49:05

+0

@Daneo,忘了吧,水平方向確實是隱式設置的。 – nikis 2014-08-28 09:52:59