2014-01-19 42 views
0

請考慮以下帶有一個可滾動TextView和其下的兩個按鈕的XML佈局。線性佈局 - 按鈕消失

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 

    > 

    <TextView 
     android:id="@+id/description" 
     android:scrollbars = "vertical" 
      /> 


<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" > 


     <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/button1" 
     /> 


    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/button2" 
     /> 


</LinearLayout> 

</LinearLayout> 

TextView動態更新。如果TextView內容適合屏幕,按鈕將很好地顯示出來。但是,只要TextView內容超出屏幕大小以使用滾動條,底部的按鈕就會消失。

如何確保按鈕始終顯示,滾動條或沒有滾動條?

+1

你可以保持您的按鈕TextView的,並在LinearLayout中滾動型。 –

+0

thnks,但我希望按鈕始終可見,只有Textview可滾動 – oat

回答

1

嘗試設置maxHeight:

android:maxHeight="480dp" 

檢查屏幕尺寸和動態設置maxHeight

0

組佈局weightSum = 「2」 到線性佈局,layout_weight到每個按鈕以1

android:weightSum="2" // to the layout 

android:layout_weight="1" // to each the button 

另外您機器人:取向= 「水平」水平,這是默認的,也許你想成爲垂直,(只是說)......

編輯刪除滾動條屬性和包裹的TextView的滾動型。

+1

weightSum是** optional **。但設置它並沒有害處。 –

+1

這不是我要找的:(。我的問題與權重無關 – oat

+0

剛編輯答案 – Android