LinearLayout引力

时间:2014-03-02 17:45:17

标签: java android xml eclipse android-layout

我的xml布局有问题。 我想用xml制作我的布局,“simplemessage”会粘在顶部,“textchange”将填充并居中在屏幕中间,而“hiraganaconfbutton”会粘在底部,我尝试重力和居中,但是某些原因,它不起作用

提前感谢您的帮助

这是我的xml布局

   <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/simplemessage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/guess"
        android:textSize="19sp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/textchange"
            android:layout_width="wrap_content"
            android:layout_height="392dp"
            android:text="@string/a"
            android:textSize="60sp" />

    </LinearLayout>

    <Button
        android:id="@+id/hiraganaconfbutton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/confirm" />

</LinearLayout>

2 个答案:

答案 0 :(得分:3)

可以这样吗?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:gravity="center_horizontal"
              android:orientation="vertical" >

    <TextView
            android:id="@+id/simplemessage"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/guess"
            android:gravity="center"
            android:textSize="19sp"
            android:layout_alignParentTop="true"/>

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/simplemessage"
            android:layout_above="@+id/hiraganaconfbutton"
            android:orientation="horizontal" >

        <TextView
                android:id="@+id/textchange"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:text="@string/a"
                android:textSize="60sp" />

    </LinearLayout>

    <Button
            android:id="@+id/hiraganaconfbutton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:gravity="center"
            android:text="@string/confirm" />

</RelativeLayout>

preview

答案 1 :(得分:0)

使用相对布局如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"            
              >

    <TextView
            android:id="@+id/simplemessage"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/guess"
            android:gravity="center"
            android:textSize="19sp"
            android:layout_alignParentTop="true"/>

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/simplemessage"
            android:layout_above="@+id/hiraganaconfbutton"
            android:orientation="horizontal" >

        <TextView
                android:id="@+id/textchange"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:text="@string/a"
                android:textSize="40sp" />

    </LinearLayout>

    <Button
            android:id="@+id/hiraganaconfbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:gravity="center"
            android:text="@string/confirm" />

</RelativeLayout>