2015-10-15 64 views
0

新手android開發人員在這裏。我有這個佈局我的對話:對話框:溢出ScrollView內容

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/llParent" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <ScrollView 
     android:id="@+id/svChild" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

    ... content goes here 

    </ScrollView> 

    <Button 
     android:id="@+id/btnCancel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@id/svChild" 
     android:text="CANCEL"/> 

    <Button 
     android:id="@+id/btnOk" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@id/svChild" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:text="OK" /> 

</RelativeLayout> 

ScrollView的內容溢出屏幕,它涵蓋下面的按鈕。有時,當更改佈局的某些屬性時,按鈕已經在屏幕之外。

我想要什麼:

  • 顯示始終在屏幕底部的按鈕,沒有覆蓋,而不是外界
  • llParentsvChild的高度設置爲wrap_content這樣,如果內容是相當小,對話框不必佔用所有屏幕的高度

感謝

回答

1

使用下列可正常工作的代碼

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.demo.example.activity.ScrollDemo"> 


<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@+id/btnButton" 
    android:id="@+id/scrollView"> 

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

     //Place your content here 

    </LinearLayout> 
</ScrollView> 



<Button 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Button" 
    android:id="@+id/btnButton" 
    android:layout_alignParentBottom="true" /> 

</RelativeLayout> 

依賴關係在這裏最重要。

如果您有任何問題隨時發表評論。

+0

你好,如果內容太短,這是行不通的。彈出窗口仍佔用整個屏幕。 – KaeL

+0

將scrollview height屬性更改爲android:layout_height =「match_parent」 –

+0

仍然一樣:( – KaeL