android - Android 图像缩放与约束布局中的背景图像相同
问题描述
在我的应用程序中,我有一个地图图像和包含地图片段的图像视图。在任何设备屏幕中,地图片段的大小应与其在地图图像中的相应部分相同。地图图像也包含在约束内的图像视图中布局。
如何使地图图像周围的图像与主图像中的图像大小相同/相等。我使用“Batch Drawable Import”插件创建了图像集。当我将图像放入 drawable-xxhdpi drawable-xhdpi drawable-hdpi drawable-ldpi 文件夹时,它们在设备上运行时会显示更大或更小的部分。这些图像片段将被拖放到最终创建地图的地图视图中。
<?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:id="@+id/parentcl"
tools:context=".Act2_1">
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/x2"
app:layout_constraintBottom_toTopOf="@+id/imageView35"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/imageView35"
app:layout_constraintVertical_bias="0.498" />
<ImageView
android:id="@+id/imageView33"
android:layout_width="163dp"
android:layout_height="0dp"
android:layout_marginBottom="38dp"
android:layout_marginEnd="368dp"
android:layout_marginTop="92dp"
app:layout_constraintBottom_toTopOf="@+id/imageView35"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/x1" />
</android.support.constraint.ConstraintLayout>
以上是我正在尝试的测试代码。BG 图像大小为 2048px X 1496px,其中红色框大小为 400px X 300px。外部图像视图中的图像块为 400px X 300px。我希望外部图像大小与背景图像中的图像大小相同。实现上述要求的最佳解决方案是什么。我尝试将图像放在应用程序内的所有可绘制文件夹中,但没有成功。然后我只在 drawable 和 drawable-nodpi-v4 文件夹中添加了一个大型图像,这也没有给出好的结果。
解决方案
推荐阅读
- jaxb - JAXB - 以小写字母开头的重复元素
- python - 有效地从熊猫字典列中提取数据
- pandas - Pandas DataFrame 和系列 - IB TWS 历史数据
- perl - 用不一致的记录分隔符/行读入文件
- sql - Oracle SQL:在 CASE 语句中使用相同的别名在一种情况下选择一列,在其他两列和另外三列中选择相同的别名
- sql - 在 SQL 中选择列值和下一个最高列值
- java - Spring Boot WebMvcTest,这里是什么导致了 IllegalArgumentException?
- java - 在不配置 JobLauncher 的情况下异步启动 Spring 批处理作业
- node.js - Google App Engine:Google App Engine 垃圾邮件日志连接拒绝 Redis,但它正在工作
- applescript - 在Finder中获取文件的文件路径