简体   繁体   English

Android布局对齐textview和按钮

[英]android layout alignment textview and button

I have attached the contents of an xml file. 我已经附上了xml文件的内容。 What I want to do is put the TextView in the center of the Row and the button aligned from the right. 我想做的是将TextView放在Row的中心,并将按钮从右对齐。 I have tried several solutions and yet I still haven't found the correct one. 我已经尝试了几种解决方案,但仍然没有找到正确的解决方案。 Any suggestions? 有什么建议么?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="*">
        <TextView
            android:id="@+id/serviceTitle"
            android:textSize="20px"
            android:textStyle="bold"
            android:gravity="center_horizontal"/>
        <Button 
            android:layout_gravity="center_horizontal"
            android:id="@+id/testButton"
            android:background="@drawable/go_button">
        </Button>
    </TableRow>
    <ListView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" 
        android:id="@android:id/list">
     </ListView>
     <TextView android:id="@android:id/empty"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Empty set"/>
</LinearLayout>

This the things you want? 这东西你想要吗?

    <RelativeLayout android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
        android:id="@+id/serviceTitle"
        android:textSize="20px"
        android:textStyle="bold"
        android:text="text view"
        android:layout_centerHorizontal="true"/>
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/testButton"
        android:text="Button"
        android:layout_alignParentRight="true">
    </Button>
    </RelativeLayout>
<ListView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1" 
    android:id="@android:id/list">
 </ListView>
 <TextView android:id="@android:id/empty"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="Empty set"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM