2014-10-04 57 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