简体   繁体   English

ScrollView不适用于imageviews

[英]ScrollView doesn't work with imageviews

I want to display 2 ImageView in my scrollview like this , but it doesn't work. 我想,以显示我的滚动视图像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> 

If i don't use android:fillViewport="true" , i see the 2 image but they are resized. 如果我不使用android:fillViewport =“ true”,我会看到2张图片,但它们的大小已调整。 If i use, size is correct but i can't get down to the second image. 如果我使用的话,尺寸是正确的,但是我无法查看第二张图片。 Why ? 为什么呢

Thanks 谢谢

If you want to see both the images as per their sizes, you should use 如果要按尺寸查看两个图像,则应使用

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

instead of 代替

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

Hope this helps. 希望这可以帮助。

You can get Screen width and height programmatically and then set the Width and height of ImageView respectively. 您可以通过编程获取Screen的宽度和高度,然后分别设置ImageView的宽度和高度。 Here is the code : 这是代码:

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();
}

Maybe the problem is that you have the image resources in the wrong folder? 也许问题是图像资源放在错误的文件夹中? try removing the "fillViewport" and move the images on a lower dpi folder (from hdpi to mdpi or from mdpi to ldpi) this will change the "dp" (density-independent pixels) of the image, making them bigger on every screen. 尝试删除“ fillViewport”并将图像移至较低dpi文件夹(从hdpi到mdpi或从mdpi到ldpi),这将更改图像的“ dp”(与密度无关的像素),从而使它们在每个屏幕上都更大。

Also, why both images have a width and height of "match_parent" ? 另外,为什么两个图像的宽度和高度都为“ match_parent”? wouldn't that make them both occupy the entire LinearLayout ? 那不是会使它们都占据整个LinearLayout吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM