我一直在尝试让大图像(10345x1280 像素)适合我的 android 屏幕(在横向模式下)基本上我希望 1280 像素的尺寸适合屏幕的高度,我希望更长的尺寸可从左向右滚动。
我一直在使用各种方法,但由于滚动不工作或图像未正确缩放,我真的没有太多运气。现在我正在尝试在 ScrollView 中使用 ImageView ,主要问题是将 ImageView 嵌入 ScrollView 会扰乱图像的缩放比例。附上imageview嵌入scroll view前后的对比图。
第一张图片是我试图通过滚动实现的理想效果,所以如果有人知道最好的方法是什么,我将不胜感激。
谢谢
http://i.imgur.com/OWkPNqp.png http://i.imgur.com/YGIdEY1.png
编辑:我对 xml 代码做了一些调整,我还调整了我的图像的高度为 400(所以它现在是 3233x400)。图片现在更适合屏幕,但仍然不完美,它向上/向下滚动但不是我需要的左右......必须有一种方法可以正确地适合图像,以便高度填满屏幕在所有设备类型上?
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0099cc"
tools:context=".FullscreenActivity"
android:nestedScrollingEnabled="true">
<!-- The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc. -->
<TextView android:id="@+id/fullscreen_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
android:textColor="#33b5e5"
android:textStyle="bold"
android:textSize="50sp"
android:gravity="center"
android:text="@string/dummy_content" />
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="0dp" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
tools:context=".HelpActivity"
android:layout_gravity="center">
<ImageView
android:id="@+id/imageHelp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:layout_marginTop="0dp"
android:src="@drawable/fretz" />
</LinearLayout>
</ScrollView>
</FrameLayout>
最佳答案
你的布局有很多问题,首先是 ScrollView 中的嵌套布局 LinearLayout
只包含不必要的 ImageView,而且 ScrollView
会自动滚动图片的垂直轴而不是水平轴考虑使用适合您需要的 HorizontalScrollView
。
我使用 HorizontalScrollView
重新制作了您的布局以水平滚动它,效果很好:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0099cc"
tools:context=".FullscreenActivity" >
<TextView
android:id="@+id/fullscreen_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:keepScreenOn="true"
android:text="SAMPLE"
android:textColor="#33b5e5"
android:textSize="50sp"
android:textStyle="bold" />
<HorizontalScrollView
android:layout_width="500dp"
android:layout_height="fill_parent"
android:layout_marginTop="0dp" >
<ImageView
android:id="@+id/imageHelp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/lal" />
</HorizontalScrollView>
</FrameLayout>
关于android - 使用 imageview (Android) 滚动宽图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25298318/