2011-12-11 53 views
0

我想讓兩個android按鈕出現在兩個textviews之間。但是第一個textview似乎正在顯示,而另一個textview和按鈕沒有出現。我希望它看起來像:如何在Textviews中放置按鈕

「等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等按鈕等等等等等等等等等等blahblah等等等等等等等等等等BUTTON」

什麼我看到的是:

「等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等」

下面是代碼:

<LinearLayout android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
    <TextView 
     android:text="Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah " 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
    <Button 
     android:text="BUTTON" 
     android:background="@null" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
    <TextView 
     android:text=" blah blah blah blah blah blahblah blah blah blah blah blah " 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
    <Button 
     android:text="BUTTON" 
     android:background="@null" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 

任何幫助將不勝感激!

回答

0

嘗試下面的代碼,並記住其重量屬性設置爲1的控制將平均調整accroding他們的寬度,如果寬度屬性設置爲FILL_PARENT

<LinearLayout android:layout_width="fill_parent" 
    android:orientation="horizontal" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent"> 
    <TextView 
     android:text="Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah " 
     android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="fill_parent"/> 
    <Button 
     android:text="BUTTON" 
     android:background="@null" 
     android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="fill_parent" android:textColor="#ffffff"/> 
    <TextView 
     android:text=" blah blah blah blah blah blahblah blah blah blah blah blah " 
     android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="fill_parent"/> 
    <Button 
     android:text="BUTTON" 
     android:background="@null" 
     android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="fill_parent" android:textColor="#ffffff"/> 
</LinearLayout> 

enter image description here

1

你最好使用佈局權重或相對佈局來實現你想要的。

檢查此以瞭解更多佈局信息。

http://developer.android.com/guide/topics/ui/layout-objects.html

+0

您好Serdar,感謝您的快速響應,請您提供一個如何使用佈局權重來實現我想要的示例? – c8apps

+0

檢查這個鏈接這是你的最好例子。 http://developer.android.com/resources/tutorials/views/hello-linearlayout.html –

0

你可以提供「佈局寬度」屬性作爲「dp」值很容易。

另一件關於你的代碼不適合你的問題。你可能在這裏使用帶有值的「android:text」屬性來清楚地表達你的問題。但如果不是,這是一個不好的做法。嘗試將字符串值始終放在「strings.xml」文件中,您可以在「values」目錄下找到它。