简体   繁体   中英

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. 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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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