1

アプリの背景にグラデーションを使用して xml ファイルを作成し、同時にロゴを入れる方法はありますか。

そのため、レイアウトの背景を設定すると、ロゴのグラデーションが表示されます。

もちろん、グラデーションを定義して、すべてのページにロゴをドロップすることもできますが、私がより良い方法で達成したいのではありませんか?

xml ファイルで両方を結合しようとしましたが、うまくいかず、アプリがクラッシュしました。

xml とロゴで作成したグラデーションは、画像 1 つで 1 つの xml ファイルにして、すべてのページで使用します。background.xml のロゴを変更すると、他のすべてのページでロゴを変更する必要があります。

次の xml をすべてのレイアウトの背景として使用したい

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
    android:startColor="#000"
    android:endColor="#008d36"
    android:gradientRadius="326"
    android:type="radial"/>
</shape>


<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginRight="18dp"
    android:layout_marginTop="89dp"
    android:layout_toLeftOf="@+id/logo"
    android:src="@drawable/logo" />
4

1 に答える 1

4

はい、XMLレイアウトからグラデーションを付けることは可能です。

しかし、あなたのシナリオでは、ロゴのグラデーションを配置したいですか?

要件について簡単に説明してください。

resにドローアブルフォルダを作成し、gradient.xmlという名前のxmlを作成して、これらのコードをコピーします。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<gradient
    android:endColor="#008d36"
    android:gradientRadius="326"
    android:startColor="#000"
    android:type="radial" />

</shape>

また、これらのコードをメインのlayout/main.xmlに正しく配置してください

<?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" >
   <RelativeLayout
    android:id="@+id/imageView1"
    android:layout_width="100dip"
    android:layout_height="100dip"
    android:background="@drawable/gradient" >

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:src="@drawable/yourlogoimage" />
    </RelativeLayout>

</LinearLayout> 
于 2013-03-15T10:31:49.720 に答える