簡體   English   中英

ScrollView不適用於imageviews

[英]ScrollView doesn't work with imageviews

我想,以顯示我的滾動視圖像2 ImageView的這個 ,但它不工作。

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


    <LinearLayout 
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">





<ImageView
    android:id="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center" />


<ImageView
    android:id="@+id/imageB"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/image"
    android:gravity="center" />

</LinearLayout>
</ScrollView> 

如果我不使用android:fillViewport =“ true”,我會看到2張圖片,但它們的大小已調整。 如果我使用的話,尺寸是正確的,但是我無法查看第二張圖片。 為什么呢

謝謝

如果要按尺寸查看兩個圖像,則應使用

<ImageView
...
android:layout_height="wrap_content"
.../>

代替

<ImageView
...
android:layout_height="match_content"
.../>

希望這可以幫助。

您可以通過編程獲取Screen的寬度和高度,然后分別設置ImageView的寬度和高度。 這是代碼:

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
try { 
display.getRealSize(size);
int width = size.x;
int height = size.y;
} catch (NoSuchMethodError e) {//to deal with API 8
int height = display.getHeight();
int width = display.getWidth();
}

也許問題是圖像資源放在錯誤的文件夾中? 嘗試刪除“ fillViewport”並將圖像移至較低dpi文件夾(從hdpi到mdpi或從mdpi到ldpi),這將更改圖像的“ dp”(與密度無關的像素),從而使它們在每個屏幕上都更大。

另外,為什么兩個圖像的寬度和高度都為“ match_parent”? 那不是會使它們都占據整個LinearLayout嗎?

暫無
暫無

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

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