在android中布局的隐形元素

时间:2011-12-15 23:23:57

标签: android android-layout

我想制作类似下面的内容。但由于某种原因,按钮是不可见的。任何人都可以帮助

--------------------
 txt1          txt2
--------------------
|                  |
|                  |
|                  |
|     txtview1     |
|                  |
|                  |
|                  |
--------------------
|btn1|        |btn2|
--------------------

布局代码:

                        <?xml version="1.0" encoding="utf-8"?>

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

                <TextView
                    android:id="@+id/txt1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"            
                    android:text="Network Status:     "/>

                <TextView
                    android:id="@+id/txt2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="updating..."
                    android:layout_toRightOf="@+id/txt1"/>

                <ScrollView
                    android:id="@+id/sv1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_below="@id/txt1">

                    <TextView
                        android:id="@+id/txt3"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:text="Log"/>

                </ScrollView>

                 <Button
                    android:id="@+id/btn1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Start"
                    android:layout_below="@+id/sv1"/>

                 <Button
                    android:id="@+id/btn2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Stop"
                    android:layout_toRightOf="@+id/btn1"
                    android:layout_below="@+id/sv1"/>


            </RelativeLayout>

2 个答案:

答案 0 :(得分:2)

问题是,ScrollView填充了剩下的空间。您可以使用fill_parent属性,但ScrollView必须高于按钮。因此,在ScrollView中,将layout_above设置为其中一个按钮。

答案 1 :(得分:1)

如果使用RelativeLayout

,则需要使用元素的定位属性

会有android:layout_alignParentTop="true"android:layout_below="@id/yourelement

等选项
相关问题