簡體   English   中英

Android ScrollView不會包裝到其子級嗎?

[英]Android ScrollView Doesn't wrap to its child?

我的ScrollView有問題。 它里面有一個ImageView。 imageView包含480 * 3000 px的圖像。 因此,它必須在ScrollView中,以便用戶能夠向下滾動。

問題是:當我測試應用程序時,ScrollView不會包裝到圖像較高的位置。 圖像下方有一個黑色空間,這對我來說很奇怪。

這是我的XML代碼。 期待您的意見

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <ScrollView
    android:id="@+id/scroll_view"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scrollbars="vertical" >    
        <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/image"
        android:src="@drawable/image01"
        android:scaleType="fitStart" />     
    </ScrollView>
</RelativeLayout>

更新:這是使用@ruhalde代碼顯示的圖像。 我無法進行屏幕截圖,因為它很大,您看不到整個圖片,所以我將其繪制出來。

在此處輸入圖片說明

重寫您的布局。 使ScrollView成為最外面的元素。 看看這個很好的教程以獲取更多信息: http : //mobiforge.com/designing/story/understanding-user-interface-android-part-1-layouts

使用LinearLayout代替目前不推薦使用的RelativeLayout。 在ScrollView XML中設置fillViewPort = true,或者如果需要,通過編程設置setFillViewPort(true)。

將imageview放在LinearLayout和ScrollView內,您的XML應該如下所示:

LinearLayout --- ScrollView ---- LinearLayout ------ ImageView

在這里查看我的XML,可以很好地處理800 x 4000像素的圖像,並且可以垂直垂直滾動:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ScrollView android:id="@+id/scrollView1"
        android:layout_width="fill_parent" android:layout_height="wrap_content">
        <LinearLayout android:id="@+id/linearLayout1"
            android:layout_width="fill_parent" android:layout_height="fill_parent">
            <ImageView android:id="@+id/mapa" android:layout_height="wrap_content"
                android:layout_width="wrap_content"></ImageView>
        </LinearLayout>
    </ScrollView>

</LinearLayout>

對於那些可能感興趣的人:

我的問題是我使用的圖像,而不是布局方式。 謝謝。

我相信您應該在布局標簽之前使用scrollView標簽

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM