Android:xml 图像缩放不足以增加图像大小

标签 android xml imageview scale

我正在开发一个带有自定义对话框的应用程序。在该对话框内,我在代码中设置了一个图像,具体取决于单击 ListView 中的哪个项目。对话框中的所有内容均有效。图像与按钮和文本一起显示。然而,我使用的图像仍然比我想要的小得多。我试着关注 this教程,但它不会将图像放大超过一点。它会缩小它们,但不会放大。我尝试了各种方法来解决这个问题,包括不同的 android:scaleType="",但都无济于事。任何帮助将不胜感激。我想避免单独设置大小,因为我有超过 400 张图像,我希望它们设置一次并在 xml 中完成。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">

<ImageView android:id="@+id/ImageView01"
 android:contentDescription="@string/desc"
 android:saveEnabled="true"
 android:adjustViewBounds="true"
 android:scaleType="fitXY"
 android:maxWidth="375dp"  
 android:maxHeight="375dp"
 android:layout_width="wrap_content" android:layout_height="wrap_content"
 android:layout_centerHorizontal="true" />

 <ScrollView android:id="@+id/ScrollView01"
 android:layout_width="wrap_content" android:layout_below="@+id/ImageView01"
 android:layout_height="wrap_content">

 <TextView android:id="@+id/TextView01"
 android:layout_width="wrap_content" android:layout_height="wrap_content"
 android:paddingLeft="5dp" />

 </ScrollView>

 <Button
 android:id="@+id/Button01"
 android:layout_width="150dp"
 android:layout_height="50dp"
 android:layout_alignParentRight="true"
 android:layout_below="@+id/ScrollView01"
 android:background="@drawable/border"
 android:text="@string/cancel"
 android:textColor="#ffffff" />

 <Button
 android:id="@+id/Button02"
 android:layout_width="150dp"
 android:layout_height="50dp"
 android:layout_below="@+id/ScrollView01"
 android:background="@drawable/border"
 android:text="@string/copy"
 android:textColor="#ffffff" />

 </RelativeLayout>

最佳答案

将您的图像放入/res/drawable-nodpi 文件夹(或相应地更改代码并将它们放入assets/ 文件夹)。

从其他 drawable/ 文件夹中删除这些图像。告诉我们它们的尺寸。在不同方向的不同屏幕上测试它们。由于这些图像将占据整个屏幕宽度,您可能需要为不同大小的桶定制布局,但我怀疑您是否需要为不同密度的桶这样做。

关于Android:xml 图像缩放不足以增加图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17538084/

相关文章:

android - 通过午餐构建非官方 LineageOS 移植

Android.widget.framelayout 无法转换为 android.support.v4.view.viewpager

java - 如何连接远程sql server数据库?

c# - 是否可以保存当前的 XMLReader Position 供以后使用?

xml - <?..?> 在 XML 中是什么意思?

Android:我想改变我的 ImageView 的颜色

imageview - 使用 fxml/javafx 加载 .tif/.tiff

android - 将 Canvas 大小设置为与位图图像相同的大小

Android Sqlite 数据库架构

php - MySql 查询以检索 xml 的元素属性的值