【问题标题】:Android TextView and Button alignmentAndroid TextView 和 Button 对齐
【发布时间】:2014-02-18 08:19:53
【问题描述】:

请帮我解决这个问题!我是 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>

帮帮我!

【问题讨论】:

    标签: android uitableview textview android-tablelayout tablerow


    【解决方案1】:

    使用

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

    【讨论】:

    • 嗨 subha,感谢您的回答,但它不起作用。实际上 tablerow 是我的单独 xml,我通过表格布局 xml 膨胀这个 xml
    • 请检查一下我已经上传了我的截图'
    【解决方案2】:

    尝试在 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>
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-02
    • 2015-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-01
    相关资源
    最近更新 更多