2010-09-29 48 views

回答

154

只是包裝所有的一個ScrollView內:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <!-- Here you put the rest of your current view--> 
</ScrollView> 

正如David Hedlund的說,ScrollView可以只包含一個項目......所以如果你有這樣的事情:

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

您必須將其更改爲:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <!-- bla bla bla--> 
    </LinearLayout> 
</ScrollView> 
+9

+1內。快速提示:「ScrollView」只能包含一個孩子,所以如果你目前得到的是很多視圖,你需要將它們包裝在一個視圖組中(比如'LinearLayout') – 2010-09-29 06:23:06

+1

謝謝@David Hedlund – 2010-09-29 06:35:50

+0

如何解決我的問題,請幫助我http://stackoverflow.com/questions/38588702/why-my-scrollview-not-working-properly – Karthi 2016-07-26 13:41:36

29

對於使用滾動視圖與相對佈局沿:

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true"> <!--IMPORTANT otherwise backgrnd img. will not fill the whole screen --> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     android:background="@drawable/background_image" 
    > 

    <!-- Bla Bla Bla i.e. Your Textviews/Buttons etc. --> 
    </RelativeLayout> 
</ScrollView> 
+0

什麼是視口標記 – 2016-10-13 18:04:02

0

如果你甚至沒有得到做什麼,上面寫的是後滾動.....

設置android:layout_height="250dp"或者你可以說xdp其中x可以是任何數值。

1

只是包裝所有的滾動型

<?xml version="1.0" encoding="utf-8"?> 

<ScrollView 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.ruatech.sanikamal.justjava.MainActivity"> 
<!-- Here you put the rest of your current view--> 
</ScrollView> 
相關問題