【发布时间】:2011-09-20 23:38:42
【问题描述】:
我想在不调整图像大小的情况下显示比设备屏幕更大的图像。它必须在屏幕上居中。我该怎么做?
【问题讨论】:
标签: android image resize scroll android-imageview
我想在不调整图像大小的情况下显示比设备屏幕更大的图像。它必须在屏幕上居中。我该怎么做?
【问题讨论】:
标签: android image resize scroll android-imageview
将滚动视图与图像视图一起使用并设置该滚动视图的高度
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/accountIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</ScrollView>
【讨论】:
layout_gravity="center"。另请注意,在现代 Android 中,fill_parent 已被弃用,并且在所有情况下都可以安全地替换为 match_parent(因为它们的作用完全相同)。
我注意到我需要使用正常(垂直)和水平 ScrollView 才能滚动两个方向。如果有其他方法,请告诉我。
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/horizontalScrollView">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView3"
android:src="@drawable/big_map"/>
</HorizontalScrollView>
</ScrollView>
它从图像的左上角开始显示。如果我尝试使用 android:layout_gravity="center" 那么我在右侧或底部得到白色部分。所以居中对我不起作用。
选项 2:使用 WebView 控件,并使用图像 onCreate 加载它。
【讨论】:
从 View 派生,覆盖 onDraw 并在屏幕上绘制。
【讨论】:
您也可以使用框架布局。布局可以比屏幕大
【讨论】: