【问题标题】:change the % of an image view in the xml layout更改 xml 布局中图像视图的百分比
【发布时间】:2014-05-28 09:37:38
【问题描述】:

我有一个非常大的图像(超过 1000 像素超过 1000 像素),当我做一个图像按钮并将图像放入其中时,我无法看到整个图像。 如何更改图像的百分比,以便在不更改 px 本身的情况下呈现它?

改变 layout_height 和 layout_width 只是改变图像按钮本身的实际大小,而不是图像大小。

<ImageButton
    android:id="@+id/imageButton1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scaleType="center"
    android:src="@drawable/black" />

<ImageButton
    android:id="@+id/imageButton1"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:scaleType="center"
    android:src="@drawable/black" />

对我没有帮助...

【问题讨论】:

  • 将 android:scaleType="fitXY" 添加到图像..
  • 你不应该将这么大的图像放在图像按钮中。

标签: android image imageview imagebutton


【解决方案1】:

将 scaleType 设置为 fitCenter:

android:scaleType="fitCenter"

【讨论】:

    【解决方案2】:

    可绘制 在名为 drawable 的 res 文件夹中创建文件夹,名称必须相同

    然后创建一个名为scale的xml文件并将这段代码放入其中

    <?xml version="1.0" encoding="utf-8"?>
    <scale xmlns:android="http://schemas.android.com/apk/res/android"
        android:drawable="@drawable/black"
        android:scaleGravity="center_vertical|center_horizontal"
        android:scaleHeight="80%" <!-- or what ever value you want % -->
        android:scaleWidth="80%" /> <!-- or what ever value you want % -->
    

    布局

       <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/scale" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-06
      • 1970-01-01
      • 2018-03-16
      • 1970-01-01
      • 2012-03-12
      • 1970-01-01
      相关资源
      最近更新 更多