将线性布局中的按钮与四个文本视图对齐

时间:2014-04-07 11:04:20

标签: android android-layout

创建一个包含4个文本视图和按钮文本视图的线性布局,一个接一个地正确对齐,但在那些文本视图下面我放置一个按钮但是它正确对齐我在附加屏幕

enter image description here

这里按钮宽度我给予包装内容然后文本也没有正确显示 检查这个xml

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="5dp"
        android:text="We are unable to process yoour request due to \n one of the following reasons: \n" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="40dp"
        android:text="1.The MOT test number does not exsist" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="40dp"
        android:text="The V5C document reference number \n does not exist or does not match the \n vehicle registration mark" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Button" />

</LinearLayout>

5 个答案:

答案 0 :(得分:0)

在按钮属性中尝试此操作 -

android:gravity="center" 

答案 1 :(得分:0)

将所有内容放入线性布局

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="5dp"
        android:gravity="center"
        android:text="We are unable to process yoour request due to \n one of the following reasons: \n" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="40dp"
        android:gravity="center"
        android:text="1.The MOT test number does not exsist" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="40dp"
        android:gravity="center"
        android:text="The V5C document reference number \n does not exist or does not match the \n vehicle registration mark" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:text="Button" />

</LinearLayout>

答案 2 :(得分:0)

<Button
        android:id="@+id/button1"
            android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="40dp"
        android:background="#ffffff"
        android:gravity="center"
        android:text="Sign In"
        android:textColor="#000000" />

答案 3 :(得分:0)

请尝试此代码

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="5dp"
        android:text="We are unable to process yoour request due to \n one of the following reasons: \n" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="1.The MOT test number does not exsist" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="     The V5C document reference number \n     does not exist or does not match the \n     vehicle registration mark" />
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="5dp"
        android:text="Button" />

</LinearLayout>

答案 4 :(得分:0)

这是eclipse问题刚刚重新开始我的日食和我的电脑,现在对齐是好的。它的工作原理。