2

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>
MahdiSa
  • 101
  • 1
  • 9

4 Answers4

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>  
Amresh
  • 2,098
  • 16
  • 20
  • Fix the android:layout_width to some numeric value .. 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" – Amresh Jun 25 '13 at 13:02
0

Use RelativeLayout and add

android:layout_toRightOf="@+id/textviewid" 

to Button.

Renjith
  • 5,783
  • 9
  • 31
  • 42
blganesh101
  • 3,647
  • 1
  • 24
  • 44
  • I do that but the button was placed to end of the line one of text view horizontally , so that's not work – MahdiSa Jun 25 '13 at 05:58
0

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>
Mayank Saini
  • 3,017
  • 24
  • 25
  • that's still not work , the button place end of the line one horizontally – MahdiSa Jun 25 '13 at 06:15
  • I post it on my question , tanks for your atention – MahdiSa Jun 25 '13 at 11:35
  • Your XML shows that u have the button before the text view and what you wanna do is button after the textview ...how would that be possible... copy paste the xml mentioned above where the textview is before the button – Mayank Saini Jun 25 '13 at 12:28
  • fix the value of android:layout_width="100dp" – Mayank Saini Jun 25 '13 at 13:18
  • Well I use right of gravity for my layout so if put button after textView that's not work . I really confused ... I think because of the textview width is constant for all lines , my button take wrong position . I mean because of this , it take end of line one X . so how could find end of last line position ? – MahdiSa Jun 25 '13 at 20:23
0

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