【发布时间】:2018-08-25 07:29:20
【问题描述】:
我有一个尺寸为3000 x 1500 像素的图像。我希望它垂直适合屏幕,并且我应该能够水平滚动它。
GITHUB 中的项目:https://github.com/rameezalam/imagescrolldemo https://github.com/rameezalam/imagescrolldemo/archive/master.zip
图片链接:https://github.com/rameezalam/imagescrolldemo/raw/master/app/src/main/res/drawable/peace.jpg
以下是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBlue"
tools:context=".MainActivity">
<HorizontalScrollView
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/colorPink"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@color/colorYellow"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:src="@drawable/peace" />
</LinearLayout>
</HorizontalScrollView>
</android.support.constraint.ConstraintLayout>
在布局文件的 Android Studio 预览中,我可以发现它按预期工作。
实机一加3T安卓8.0.0,如下图所示
- compileSdkVersion 27
- minSdkVersion 15
- targetSdkVersion 27
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
编辑
所以在为我的布局添加背景颜色之后,我得到了以下内容。看起来图像视图没有扩展到其父视图。
【问题讨论】:
-
您是否在真实设备中尝试了 3000 x 3000 的图像..?我想是因为这个
-
你可以尝试在水平滚动视图高度使用 match_parent 吗?
-
试试我之前问过你的图片...使图片高度超过1500
标签: android imageview horizontalscrollview