0

アクティビティを通じてこれを行う方法についていくつかの解決策を見つけましたが、レイアウトとグラフィックスにxmlを使用することに固執したいと思います。

プレーンなデフォルトの角ではなく、丸みを帯びたエッジを持つボタンに画像を設定したいと思います。

XMLサンプル:

<ImageView
                android:id="@+id/featuredimage"
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:clickable="true"
                android:background="@drawable/rounded"
                android:src="@drawable/budlight_sample"
                android:scaleType="centerCrop" />

ROUNDED.XML

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

    <corners
        android:bottomLeftRadius="10dp"
        android:bottomRightRadius="10dp"
        android:topLeftRadius="10dp"
        android:topRightRadius="10dp" >
    </corners>

</shape>
4

2 に答える 2

1

丸みを帯びた角にドローアブル形状を使用し、アプリのドローアブルフォルダにrounded.xmlを定義します。

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape=["rectangle" | "oval" | "line" | "ring"] >
    <corners
        android:radius="integer"
        android:topLeftRadius="integer"
        android:topRightRadius="integer"
        android:bottomLeftRadius="integer"
        android:bottomRightRadius="integer" />
</shape>

参照:http ://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

layout.xmlファイルで、ビューの背景としてrounded.xmlを使用します。

android:background="@drawable/shape"
于 2012-08-30T17:40:31.717 に答える
0

xmlファイルに図形を描画してから呼び出します。

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="rectangle"> 
     <gradient android:startColor="#Anycolor" android:endColor="#Anycolor" 
            android:angle="90"/> 

    <corners android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp" 
     android:topLeftRadius="10dp" android:topRightRadius="10dp"/> 
</shape> 

もう1つのオプションは、draw9patchを使用することです。ただし、そのためのカスタム画像ボタンを作成する必要があります。上記のコードを使用する方がはるかに簡単です。

于 2012-08-30T17:34:28.677 に答える