2

我正在开发一个包含一些文本视图和按钮的 Android 应用程序。

我需要将 Button 放在文本视图之后。当我的 TextView 是运行良好的单行时。但是当使用多行文本视图时,我的按钮被放置在第 1 行的末尾。

如何将按钮放置在正确的位置(在文本视图的最后一行之后)?

编辑后:
这是我的 xml,我在代码中使用它并动态生成它。

<TableLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:shrinkColumns="1"
android:stretchColumns="1"  >

   <TableRow android:id="@+id/tableRow1" >
 <Button
    android:id="@+id/ayehPlace_btnCounter"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/ayeh_counter"
    android:text="" />
<TextView
    android:id="@+id/ayehPlace_txtAyeh"
    android:layout_width="wrap_content"
    style="@style/ayehPlace_txt"
    android:layout_height="wrap_content"
    android:text="" /> 
</TableRow>
</TableLayout>
4

4 回答 4

1

改用表格布局..它对我有用..

<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingTop="10dp"
    android:shrinkColumns="1"
    android:stretchColumns="1" >

    <TableRow
        android:descendantFocusability="beforeDescendants"
        android:focusable="true"
        android:focusableInTouchMode="true" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Your Text" />

        <Button
            android:id="@+id/button_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""/>
    </TableRow>
    </TableLayout>  
于 2013-06-25T06:50:29.947 回答
0

使用 RelativeLayout 并添加

android:layout_toRightOf="@+id/textviewid" 

到按钮。

于 2013-06-25T05:50:54.473 回答
0

我认为,您需要将 TableLayout 与 android:gravity="bottom" 一起使用。试试看。

于 2013-06-25T07:10:24.363 回答
0

我更喜欢使用表格布局。它使 UI 统一并自动调整

<TableLayout
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="fill_parent"
       android:layout_height="match_parent"
       android:padding="5dp"
       android:shrinkColumns="1"
       android:stretchColumns="1" >

       <TableRow android:id="@+id/tableRow1" >

           <TextView
               android:id="@+id/textView1"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:text="Main Status             "
               android:textAppearance="?android:attr/textAppearanceMedium" />

           <Button
               android:id="@+id/retentionMainStatus"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:text="CLICK ME" />
</TableRow>
</TableLayout>
于 2013-06-25T06:06:19.653 回答