[英]Scale a drawable resource in XML (Android)
I'm trying to scale a drawable to the double of its original size.I'm trying to use this: Drawable Resouces . 我正在尝试将drawable缩放到原始大小的两倍。我正在尝试使用它: Drawable Resouces 。 My current code is:
我目前的代码是:
Drawable: 绘制对象:
<?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>
Layout: 布局:
<?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>
But nothing is shown in the second ImageView. 但是第二个ImageView中没有显示任何内容。 How can I fix it?
我该如何解决?
Drawable 可绘制
<?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%" />
layout 布局
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/scale" />
try like this or you may check this link. 尝试这样或你可以查看此链接。
http://developer.android.com/guide/topics/resources/drawable-resource.html http://developer.android.com/guide/topics/resources/drawable-resource.html
Once i had this problem i found the solution by using inset instead of scale. 一旦我遇到这个问题,我通过使用inset而不是scale来找到解决方案。 Create a new xml drawable file in drawable folder and add you code like this:
在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"
/>
use it like this 像这样使用它
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/scale" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.