8

我正在尝试将可绘制对象缩放到其原始大小的两倍。我正在尝试使用它:Drawable Resouces。我目前的代码是:

可绘制:

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/ic_launcher"
    android:scaleHeight="80%"
    android:scaleWidth="80%" >

</scale>

布局:

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

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

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

</LinearLayout>

但是第二个 ImageView 中没有显示任何内容。我该如何解决?

4

2 回答 2

11

一旦我遇到这个问题,我就通过使用 inset 而不是 scale 找到了解决方案。在 drawable 文件夹中创建一个新的 xml 可绘制文件并添加如下代码:

<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/buttonright"
android:insetTop="4dp"
android:insetLeft="4dp"
android:insetRight="4dp"
android:insetBottom="4dp"
/>

像这样使用它

   <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/scale" />
于 2015-08-06T20:41:48.910 回答
6

可绘制

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/logo"
    android:scaleGravity="center_vertical|center_horizontal"
    android:scaleHeight="80%"
    android:scaleWidth="80%" />

布局

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

试试这样,或者你可以检查这个链接。

http://developer.android.com/guide/topics/resources/drawable-resource.html

于 2013-01-07T12:00:54.257 回答