0

我正在開發一個包含一些文本視圖和按鈕的Android應用程序。在MultiViewine TextView中TextView結束後放置按鈕?

我需要把按鈕放在文本視圖之後。當我的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> 
+0

嘗試使用android:baselineAligned =「」 – KOTIOS

+2

放置您的佈局代碼或顯示它的一些粗略草圖。 –

+0

聽起來像你正在尋找'android:gravity =「bottom」'你的(大概)水平'LinearLayout'。 –

回答

0

使用的RelativeLayout並添加

android:layout_toRightOf="@+id/textviewid" 

到按鈕。

+0

我這樣做,但按鈕被放置在文本視圖水平線的一端,所以這是行不通的 – user2518719

0

,我會更喜歡使用表格佈局instead..it使得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> 
+0

仍然無法正常工作,按鈕放置在水平線的一端 – user2518719

+0

張貼您的XML在這裏... –

+0

I post它在我的問題,坦克爲你的注意 – user2518719

0

使用表佈局,而不是....這工作對我來說..

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

這是行不通的。我添加我的XML到問題 – user2518719

+0

修復android:layout_width到一些數值..對於前 android:layout_width =「120dp」 android:layout_height =「wrap_content」 android:text =「Lorem ipsum dolor sit amet,consectetur」 android:maxLines =「5」 android:lines =「5」 – ryderz8

0

我想,你需要使用TableLayout和android:gravity =「bottom」。嘗試一下。

+0

沒有工作,但坦克 – user2518719