Android的左,中,右对齐 [英] Android Left,Center and Right Alignment

查看:116
本文介绍了Android的左,中,右对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是pretty的新Android和试图做一个示例应用程序,其中3元(2个按钮和1个文本视图)的水平放置。我需要的文本是在市中心有两个按钮左对齐,右视图。

I am pretty new to android and trying to do a sample app where 3 elements (2 buttons and 1 text view ) are placed horizontally. I need the text to be in the center with two buttons aligned left and right of the view.

例如。

|<Button>    <Text>     <Button>|

鸭preciate如果你能帮助我。

Appreciate if you could help me with this.

在此先感谢

推荐答案

编辑:我相信,这将解决您的问题。请参见下面的code。让我知道这是否有助于!我知道这已经帮了我,我会用它。接受此作为答案,如果它的工作! =)

I believe this will solve your problem. See the below code. Let me know if this helps! I know this has helped me and i will be using it. Accept this as the answer if it worked! =)

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1">
    <TableRow>
        <Button 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:text="button1" 
            android:id="@+id/button1button"></Button>
        <EditText 
            android:layout_height="wrap_content" 
            android:id="@+id/firstedittext"
            android:layout_width="wrap_content"></EditText>
        <Button 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="button2" 
            android:id="@+id/button2button"></Button>
    </TableRow>
</TableLayout>


编辑:添加相对布局,看它是否适合你,让我知道,如果它的工作原理。您将需要调整10px的,以获得所需的距离。我看到,如果有更好的方式来做到这一点,该距离为更具活力。


Added relative layout to see if it works for you, let me know if it works. You will need to adjust the "10px" to get the desired distance. I am seeing if there is a better way to do this, where the distance is more dynamic.

可以使按钮alignParentLeft和alignParentRight让他们对准屏幕的右侧和左侧。但是,我仍然无法得到这两种观点之间的文本。

You can make the buttons "alignParentLeft" and "alignParentRight" to get them to align with the right and left side of the screen. However, i am still having trouble getting the text between the two views.

您可以为布局XML文件做到这一点。使它成为一个horozontal布局,首先添加的第一个按钮,然后在文本视图,然后是第二个按钮。会后不久XML的例子。

You could do this in your xml file for the layout. Make it a horozontal layout and add the first button first, then the text view, then the second button. Will post xml shortly for an example.

    <RelativeLayout 
        android:id="@+id/LinearLayout01"
        android:orientation="horizontal" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <Button 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:text="button1" 
            android:layout_alignParentLeft="true"
            android:layout_marginRight="10px"
            android:id="@+id/button1button"></Button>
        <EditText 
            android:layout_height="wrap_content" 
            android:id="@+id/firstedittext"
            android:layout_toRightOf="@id/button1button"
            android:layout_marginRight="10px"
            android:layout_width="wrap_content"></EditText>
        <Button 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/firstedittext"
            android:text="button2" 
            android:id="@+id/button2button"></Button>
    </RelativeLayout>

这篇关于Android的左,中,右对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆