简体   繁体   English

Android TextView 和 Button 对齐

[英]Android TextView and Button alignment

在此处输入图片说明

Please help me out with this!这个你能帮我吗! I am new to android, I want to create a two text view and one button in the same Table row with three things should be aligned centred both horizontally and vertically.我是 android 新手,我想在同一个表格行中创建一个两个文本视图和一个按钮,其中三个东西应该水平和垂直居中对齐。 Here is my code it's working but there is no proper alignment and I added the snapshot of my window which doesn't align properly.这是我的代码,它正在工作,但没有正确对齐,我添加了我的窗口的快照,但它没有正确对齐。

 <TableLayout 
        android:id="@+id/exp_table"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:shrinkColumns="*"
        android:stretchColumns="*"
        >
<TableRow>
<TextView
        android:id="@+id/exp_text1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text=""
            android:layout_gravity="center_horizontal|center_vertical"
            android:textColor="#000000"
            android:layout_span="4"
            android:layout_margin="1dp" />
<EditText
            android:id="@+id/mEdttxt1"
            android:layout_width="80dp"
            android:layout_marginTop="2dp"
            android:layout_marginLeft="20dp"
            android:layout_height="30dp"
            android:background="@drawable/edittextborder"
            android:text=""
            android:inputType="number"
            android:textColor="#000000"
            android:layout_span="4"
            />
 <Button
            android:id="@+id/exp_Nxt"
            style="@style/button_text"
            android:text="Next"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="50dp"
            android:layout_marginTop="5dp"
            android:background="@drawable/red_button"/>
</TableRow>

Help Me!帮我!

Try using a LinearLayout inside your TableRow.尝试在 TableRow 中使用 LinearLayout。

Try this code:试试这个代码:

<TableRow xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
        <TextView

            android:id="@+id/exp_text1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text=""
            android:textColor="#000000"
            android:layout_span="4"
            android:layout_margin="1dp" />
        <EditText
            android:id="@+id/mEdttxt1"
            android:layout_width="80dp"
            android:layout_marginTop="2dp"
            android:layout_marginLeft="20dp"
            android:layout_height="30dp"
            android:background="@drawable/edittextborder"
            android:text=""
            android:inputType="number"
            android:textColor="#000000"
            android:layout_span="4"/>
         <Button
            android:id="@+id/exp_Nxt"
            style="@style/button_text"
            android:text="Next"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="50dp"
            android:layout_marginTop="5dp"
            android:background="@drawable/red_button"/>
</LinearLayout>

use

<TableLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:padding="5dp" >
  <TableRow >
         <TextView

            android:id="@+id/exp_text1"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:text="yourstring"
            android:textColor="#000000"

            android:layout_margin="1dp" />
<TextView
            android:id="@+id/mEdttxt1"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:hint="xxxxxxxxxxxx"
            android:inputType="number"
            android:textColor="#000000"

            />
     <Button
            android:id="@+id/exp_Nxt"

            android:text="Next"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="50dp"
            android:layout_marginTop="5dp"
          />
</TableRow>

</TableLayout>

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

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