简体   繁体   English

如何在Android XML中进行此布局

[英]How to make this layout in Android XML

I am novice in Android trying to make this layout: 我是Android的新手,尝试进行以下布局: 插图

Simply what I want to achieve: The red container should take as much space as it needs but not as much that green container have to be shrinked. 这就是我要实现的目标:红色容器应占用所需的空间,但绿色容器不必收缩。 If there are too many items, red container will be scrollable. 如果物品太多,红色容器将可滚动。 Green container is also always centered in orange one if there is space for it (if not it is actually still centered). 如果有足够的空间,则绿色容器也始终以橙色容器居中(如果没有,则实际上仍居中)。

I don't know how to do it at all :( . Here is my try: 我根本不知道该怎么做:(。这是我的尝试:

The problem is that I want to always maintain height of green container (minHeight does not work I can't understand why) and make the green container centered in orange one. 问题是我要始终保持绿色容器的高度(minHeight无法正常工作,我不明白为什么),并使绿色容器居中于橙色容器的中心。 I have problem with Scenario 2 (as you can see in the picture), this code works good in first scenario. 我在方案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>

Edit: minHeight does not help: 编辑:minHeight没有帮助: 证明minHeight不起作用

Edit: image for user Illegal Argument: 编辑:用户非法参数的图片:

在此处输入图片说明

Try setting property android:minHeight = "(whatever)dp" to orangeContainer. 尝试将属性android:minHeight =“(whatever)dp”设置为orangeContainer。 This worked for me in others "similiar" cases. 这在其他“类似”案例中对我有用。

:) :)

Is this what you are looking for: 这是你想要的:

<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>

Snapshot in ecllipse: eclipse中的快照: 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM