我是新來的android和我有以下問題: 我想分裂我的屏幕4線性佈局和我需要根佈局是相對佈局, 我試圖使用layout_weight屬性爲了在屏幕上同樣地分割我的4佈局,但是我只能成功地做到這一點,當我使用根佈局作爲線性佈局。 佈局XML:android layout_weight與RelativeLayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/view_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:splitMotionEvents="false">
<LinearLayout
android:id="@+id/top_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:id="@+id/a_status_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#5080ce">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="A status"/>
</LinearLayout>
<LinearLayout
android:id="@+id/b_status_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#356dc6">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="B status"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/bottom_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
>
<LinearLayout
android:id="@+id/c_status_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#325287">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="C status"/>
</LinearLayout>
<LinearLayout
android:id="@+id/d_status_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#26477c" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="D status"/>
</LinearLayout>
</LinearLayout>
(^ I關閉 'RelativeLayout的' 標籤到底,由於某種原因,它未示出)
This is the screen when the root layout is LinearLayout
And this is when it's RelativeLayout(如在上面的xml)
我可以使用'dp'單位將屏幕分割爲4,但這樣我就遇到了問題其他的東西...... 我的主要目標是能夠將浮動圖片從一種佈局拖放到另一種佈局,我需要使用relativeLayout,另外我想知道在哪種佈局下圖像已被丟棄,通過使用由於某些原因,它的屬性給了我虛假的位置。
非常感謝你! :)
重量只有在的LinearLayout容器的工作。加權的維度必須是** 0dp **。 –