8

ドローアブルを元のサイズの2倍に拡大縮小しようとしています。これを使用しようとしています:ドローアブルリソース。私の現在のコードは次のとおりです。

ドローアブル:

<?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>

ただし、2番目のImageViewには何も表示されません。どうすれば修正できますか?

4

2 に答える 2

11

この問題が発生したら、スケールの代わりにインセットを使用して解決策を見つけました。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 に答える