[英]Scale a drawable resource in XML (Android)
我正在嘗試將drawable縮放到原始大小的兩倍。我正在嘗試使用它: 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中沒有顯示任何內容。 我該如何解決?
可繪制
<?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
一旦我遇到這個問題,我通過使用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" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.