Place Button just after end of TextView in multilline TextView?

做~自己de王妃 提交于 2020-01-14 03:03:47

问题


I'm developing an Android application that contains some text view and button.

I need to put Button just after the text view. When my TextView is single line that's working well. But when using multiple line of text view , my button was placed to the end of line 1.

How to place button in the right position (after last line in the text view)?

after edit :
this is my xml , I use it in my code and generate it dynamically .

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

回答1:


Use Table Layout instead .... It worked for me ..

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



回答2:


Use RelativeLayout and add

android:layout_toRightOf="@+id/textviewid" 

to Button.




回答3:


I'll prefer to use table layout instead..it makes the UI uniform and adjusts automatically

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



回答4:


I think, you need to use TableLayout together with android:gravity="bottom". Try it.



来源:https://stackoverflow.com/questions/17290001/place-button-just-after-end-of-textview-in-multilline-textview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!