2014-10-04 52 views
0

我是新手,在Android的努力使這個佈局: Illustration如何使這個佈局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沒有幫助: Proof that minHeight does not work

編輯:圖像用戶非法參數:

enter image description here

+0

你需要支持2.3 Android版本? – eleven 2014-10-04 14:20:51

+0

這可以很容易地實現使用相對佈局 – 2014-10-04 14:22:11

+0

你的紅色視圖中的「項目」是什麼? – Squonk 2014-10-04 14:26:19

回答

0

嘗試設置屬性的android:=了minHeight 「(任何)DP」 來orangeContainer。這在其他「類似」情況下適用於我。

:)

+0

這對我不起作用。我已將證明添加到我的帖子中,請檢查它。 – 1daemon1 2014-10-04 16:06:12

+0

我會嘗試將您的頂級LinearLayout更改爲RelativeLayout,並使用android:layout_below =「xxx」來放置組件。你懂我的意思嗎?。儘管如此,minHeight的50dp是非常小的一個。例如,請用200dp檢查以獲取證明。 – 2014-10-04 16:11:54

+0

不起作用。我嘗試了數百萬次。如果您提供示例代碼,我將非常感激。對於小圖片感到抱歉,下次我會上傳更好的圖片:)。 – 1daemon1 2014-10-04 16:44:33

0

這是你在找什麼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<ScrollView 
    android:id="@+id/scrollView1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/list_items" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:background="@android:color/background_dark" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 
    </LinearLayout> 
</ScrollView> 

<LinearLayout 
    android:id="@+id/list_items" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:background="@android:color/darker_gray" 
    android:gravity="center" 
    android:minHeight="200dp" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="TextView" /> 
</LinearLayout> 

</RelativeLayout> 

快照在ecllipse: enter image description here

+0

謝謝,但它不是我想要的。如果有空的上部(紅色,在你的情況下是黑色)容器橙色(在你的情況下灰色)容器應該佔用所有的空間。如果紅色(在你的情況下是黑色)容器有很多,如果物品不應該在橙色容器中垂直放置空間(在你的情況下是灰色的),但橙色容器的內容必須全部可見。看看我在帖子中畫出的樣本。 – 1daemon1 2014-10-04 16:42:04

+0

我在帖子中爲您添加了描述圖片。 – 1daemon1 2014-10-04 16:53:06