我是新手,在Android的努力使這個佈局: 如何使這個佈局Android的XML
只要我想達到的目標: ,因爲它需要但不是紅色的容器應採取儘可能多的空間很多綠色容器必須縮小。如果項目太多,紅色容器將滾動。綠色容器也總是以橙色爲中心,如果有空間的話(如果沒有,它實際上仍然居中)。 。
我不知道該怎麼都做:(這裏是我的嘗試:
的問題是,我要永遠保持綠色容器的高度(不了minHeight不工作我無法理解。爲什麼),並以橙色一個綠色集裝箱中心我有問題,方案2(你可以在圖片中看到),該代碼在第一種情形下好
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:id="@+id/red_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_red_dark"
android:scrollbarAlwaysDrawVerticalTrack="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Items are here -->
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/orange_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_orange_dark"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:id="@+id/green_container"
android:layout_width="100dp"
android:background="@android:color/holo_green_dark"
android:layout_height="50dp"
android:orientation="horizontal">
<!-- My content -->
</LinearLayout>
</LinearLayout>
</LinearLayout>
編輯:了minHeight沒有幫助:
編輯:圖像用戶非法參數:
你需要支持2.3 Android版本? – eleven 2014-10-04 14:20:51
這可以很容易地實現使用相對佈局 – 2014-10-04 14:22:11
你的紅色視圖中的「項目」是什麼? – Squonk 2014-10-04 14:26:19