2017-08-21 32 views
-1

如何讓我的屏幕滾動?ScrollView和文本

如何使用ScrollView?在我的活動中,有一張圖片和文字,對我來說,在屏幕滾動時向下或向上移動是必要的。

回答

0

ScrollView XML資源相當易於使用且功能強大。只需用ScrollView標籤將您想要在XML中滾動的任何內容包裝起來,剩下的內容將會爲您處理。簡單的例子:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:scrollbars="vertical" 
android:background="@color/colorPrimary" 
android:fillViewport="true"> 

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

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/yourID" 
     android:layout_weight="1" /> 

     ... 
</LinearLayout></ScrollView> 

這個例子顯示了一個LinearLayout填充任何你需要(在這種情況下的TextView),將在屏幕上滾動時,它必須如此。