簡體   English   中英

Android TextView 和 Button 對齊

[英]Android TextView and Button alignment

在此處輸入圖片說明

這個你能幫我嗎! 我是 android 新手,我想在同一個表格行中創建一個兩個文本視圖和一個按鈕,其中三個東西應該水平和垂直居中對齊。 這是我的代碼,它正在工作,但沒有正確對齊,我添加了我的窗口的快照,但它沒有正確對齊。

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

幫我!

嘗試在 TableRow 中使用 LinearLayout。

試試這個代碼:

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

<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