我想在设备屏幕上显示比图片尺寸更大的图像,而不改变图片大小。同时需要将其居中显示在屏幕上。如何实现?
我想在设备屏幕上显示比图片尺寸更大的图像,而不改变图片大小。同时需要将其居中显示在屏幕上。如何实现?
使用带有图像视图的滚动视图,并设置该滚动视图的高度。
<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>
我注意到为了实现双向滚动,需要使用垂直和水平的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中加载图像。
您还可以使用帧布局进行工作。布局可以比屏幕更大。
layout_gravity="center"
。还要注意,在现代Android中,fill_parent已被弃用,并且可以在所有情况下安全地替换为match_parent(因为它们都执行完全相同的操作)。 - Charles Madere