【问题标题】:Place Button just after end of TextView in multilline TextView?在多行TextView中的TextView结束后放置按钮?
【发布时间】:2013-06-21 19:36:53
【问题描述】:

我正在开发一个包含一些文本视图和按钮的 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>

【问题讨论】:

  • 尝试使用 android:baselineAligned=""
  • 输入您的布局代码或显示一些粗略的草图。
  • 听起来你在(大概)水平的LinearLayout 上寻找android:gravity="bottom"
  • 你想要你的Button 就在TextView 的正下方吗?
  • 不,我希望它放在我的 textview 的结尾字符旁边

标签: android eclipse android-layout textview android-button


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 将 android:layout_width 修复为某个数值 .. for ex android:layout_width="120dp" android:layout_height="wrap_content" android:text="Lorem ipsum dolor sit amet, consectetur" android: maxLines="5" android:lines="5"
    【解决方案3】:

    我更喜欢使用表格布局。它使 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>
    

    【讨论】:

    • 还是不行,按钮将第一行的末尾水平放置
    • 我把它贴在我的问题上,坦克请注意
    • 您的 XML 显示您在文本视图之前有按钮,而您想要做的是在 textview 之后的按钮...这怎么可能...复制粘贴上面提到的 xml 到 textview在按钮之前
    • 修复android:layout_width="100dp"的值
    • 好吧,我在布局中使用了重力,所以如果在 textView 之后放置按钮,那是行不通的。我真的很困惑......我认为由于所有行的 textview 宽度都是恒定的,我的按钮位置错误。我的意思是正因为如此,它在第一行 X 结束。那么如何找到最后一行的结束位置呢?
    【解决方案4】:

    使用RelativeLayout并添加

    android:layout_toRightOf="@+id/textviewid" 
    

    到按钮。

    【讨论】:

    • 我这样做了,但是按钮被放置在水平文本视图的第一行的末尾,所以这是行不通的
    猜你喜欢
    • 2019-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多