我目前正在做一個特殊的橫向屏幕xml佈局,其中4個圖像存在和2個LinearLayouts彼此相鄰,每個圖像2個圖像。這些LinearLayouts我呼叫linearLayout1
和linearLayout2
。使兩個LinearLayouts有每個屏幕的50%,而不使用layout_weight
linearLayout1
標有藍色矩形:
linearLayout2
標有藍色矩形:
正如你所看到的,第一個使用〜的80%屏幕,而第二個使用剩下的東西。我當然不想要這個,我想每個人都要50%。我無法使用layout_weight
,因爲它已經用於LinearLayouts本身(定位兩個圖像)並且嵌套權重對性能不利。
我已經嘗試了很多不同的變化,但我根本無法讓兩個LinearLayouts每個都有50%的屏幕。下面的代碼:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/db1_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/title_container"
style="@style/TitleBar" >
<ImageView
style="@style/TitleBarLogo"
android:contentDescription="@string/imgViewDesc"
android:src="@drawable/title_logo" />
<ImageView
style="@style/TitleBarSeparator"
android:contentDescription="@string/imgViewDesc" />
<TextView style="@style/TitleBarText" />
<ImageButton
style="@style/TitleBarAction"
android:contentDescription="@string/imgViewDesc"
android:onClick="onClickAbout"
android:src="@drawable/title_about" />
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title_container"
android:layout_above="@+id/mobFoxView" >
<!-- LEFT COLUMN -->
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/mobFoxView"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/linearLayout2"
android:background="@color/white"
android:gravity="center"
android:orientation="vertical"
android:weightSum="2" >
<ImageView
android:id="@+id/imgNews"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:contentDescription="@string/imgViewDesc"
android:onClick="onClickFeature"
android:src="@drawable/front_news_1" />
<ImageView
android:id="@+id/imgReleases"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:contentDescription="@string/imgViewDesc"
android:onClick="onClickFeature"
android:src="@drawable/front_releases_1" />
</LinearLayout>
<!-- RIGHT COLUMN -->
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_above="@+id/mobFoxView"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/linearLayout1"
android:background="@color/white"
android:gravity="center"
android:orientation="vertical"
android:weightSum="2" >
<ImageView
android:id="@+id/imgArtists"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:contentDescription="@string/imgViewDesc"
android:onClick="onClickFeature"
android:src="@drawable/front_artists_1" />
<ImageView
android:id="@+id/imgLabels"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:contentDescription="@string/imgViewDesc"
android:onClick="onClickFeature"
android:src="@drawable/front_labels_1" />
</LinearLayout>
</RelativeLayout>
<com.mobfox.sdk.MobFoxView
android:id="@+id/mobFoxView"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
mode="test"
publisherId="@string/mobFoxID" />
</RelativeLayout>
無論如何,我會使用嵌套的layout_weight。表現不會那麼糟糕。 –