[英]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.