Android 如何正确定位布局

Android 如何正确定位布局,android,android-layout,Android,Android Layout,我有一个屏幕,它是 我希望按钮放在彼此下面,文本视图放在彼此下面,我的代码是 <LinearLayout android:id="@+id/LL1" android:layout_width="wrap_content" android:layout_height="wrap_content" and

我有一个屏幕,它是 我希望按钮放在彼此下面,文本视图放在彼此下面,我的代码是

<LinearLayout
                        android:id="@+id/LL1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center_vertical"
                        android:orientation="horizontal" >

                        <TextView
                            android:id="@+id/tvTab1Ask"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="ask for new question" />

                        <Button
                            android:id="@+id/bMainTabsGetQuestion"
                            android:layout_width="116dp"
                            android:layout_height="33dp"
                            android:text="Get Question"
                            android:textSize="15px" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/LL2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center_vertical"
                        android:orientation="horizontal" >

                        <TextView
                            android:id="@+id/tvTab1Join"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Join New Competition" />

                        <Button
                            android:id="@+id/bMainTabsJoin"
                            android:layout_width="wrap_content"
                            android:layout_height="30dp"
                            android:text="Join"
                            android:textSize="15px" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/LL3"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center_vertical"
                        android:orientation="horizontal" >

                        <TextView
                            android:id="@+id/tvTab1Signout"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="or you can signout" />

                        <Button
                            android:id="@+id/bMainTabsSignout"
                            android:layout_width="wrap_content"
                            android:layout_height="30dp"
                            android:text="Sign out"
                            android:textSize="15px" />
                    </LinearLayout>


我的意思是每个按钮都必须在同一点垂直启动,为什么不尝试将方向更改为垂直方向(类似于android:orientation=“vertical”)如果要垂直设置按钮和文本,请选择每个线性布局的方向?

为什么不尝试将方向更改为垂直方向(类似于
android:orientation=“vertical”
)如果您想垂直设置按钮和文本,请使用每个线性布局?

我认为当您使用
时,它将按照您的意愿工作。

我认为当您使用
时,它将按照您的意愿工作。

使用
RelativeLayout
而不是线性布局

并使用类似于android:layout_alignLeft=“”的参数
android:layout_alignBottom=“根据您的设计将其对齐。

使用
RelativeLayout
而不是LinearLayout

并使用类似于android:layout_alignLeft=“”的参数 android:layout_alignBottom=“根据您的设计对其进行对齐。

尝试以下XML格式:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TableRow
        android:id="@+id/row1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:weightSum="2" >

        <TextView
            android:id="@+id/tv1"
            android:layout_column="0"
            android:text="Ask for new Question"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_weight="1" />

        <Button
            android:id="@+id/btn1"
            android:text="Get Questiopn"
            android:layout_column="1"
            android:layout_weight="1" />
    </TableRow>

    <TableRow
        android:id="@+id/row2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:weightSum="2" >

        <TextView
            android:id="@+id/tv2"
            android:layout_column="0"
            android:text="Join new Competition"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_weight="1" />

        <Button
            android:id="@+id/btn2"
            android:text="Join"
            android:layout_column="1"
            android:layout_weight="1" />
    </TableRow>

    <TableRow
        android:id="@+id/row3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:weightSum="2" >

        <TextView
            android:id="@+id/tv3"
            android:layout_column="0"
            android:text="Or you can Signout"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_weight="1" />

        <Button
            android:id="@+id/btn3"
            android:text="Sign Out"
            android:layout_column="1"
            android:layout_weight="1" />
    </TableRow>

</TableLayout>

这是完美的工作,见下文

尝试以下XML格式:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TableRow
        android:id="@+id/row1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:weightSum="2" >

        <TextView
            android:id="@+id/tv1"
            android:layout_column="0"
            android:text="Ask for new Question"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_weight="1" />

        <Button
            android:id="@+id/btn1"
            android:text="Get Questiopn"
            android:layout_column="1"
            android:layout_weight="1" />
    </TableRow>

    <TableRow
        android:id="@+id/row2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:weightSum="2" >

        <TextView
            android:id="@+id/tv2"
            android:layout_column="0"
            android:text="Join new Competition"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_weight="1" />

        <Button
            android:id="@+id/btn2"
            android:text="Join"
            android:layout_column="1"
            android:layout_weight="1" />
    </TableRow>

    <TableRow
        android:id="@+id/row3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:weightSum="2" >

        <TextView
            android:id="@+id/tv3"
            android:layout_column="0"
            android:text="Or you can Signout"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_weight="1" />

        <Button
            android:id="@+id/btn3"
            android:text="Sign Out"
            android:layout_column="1"
            android:layout_weight="1" />
    </TableRow>

</TableLayout>

这是完美的工作,见下文



更好地使用相对性Yout是“表单”类型的最佳选项UI@ChintanRaghwani当我尝试时,butom变为向上,textview变为向下,将新的TableLayout XML添加到问题中,这样我们就可以看到发生了什么UI@ChintanRaghwani当我试过的时候,butom变为向上,textview变为向下将新的TableLayout XML添加到问题中,这样我们就可以看到发生了什么。你的意思是我必须用TableLayout替换linerlayout吗?当我这样做时,按钮变为向上,textview变为向下一行,你应该有文本和按钮。好吧……以后不要问我细节,什么时候你会接受其他像我这样的答案。我接受了他/她的答案,因为我只是复制粘贴了他的代码,因为我是android上的新手,无论如何非常感谢你,对不起,你的意思是我必须用tablelayout替换linerlayout吗?当我这样做时,按钮变为up,文本视图变为Downin一行,你应该有文本和按钮。好吧……以后不要问我细节,什么时候你会接受像我这样的回答。我接受了他/她的回答,因为我只是复制粘贴了他的代码,因为我在android上是新的,无论如何非常感谢你,很抱歉,但是布局没有找到:)但是布局没有找到:)