2012-04-26 5 views
0

buttonsアンドロイドボタン画像

と最初の2つのフィールドは、Android ICSからSMSアプリケーションであり、3つ目は、鉱山です。
私はこの方法で作られた:

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <EditText 
    android:id="@+id/searchfield" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_toLeftOf="@+id/newItem"/> 

    <ImageButton 
    android:id="@+id/newItem" 
    android:layout_height="40dip" 
android:layout_width="40dip" 
android:layout_alignParentTop="@+id/searchfield" 
android:adjustViewBounds="true" 
android:contentDescription="Add" 
android:layout_alignParentRight="true"/> 

</RelativeLayout> 

をし、画像がこのようにsettedされています

Drawable img = getResources().getDrawable(R.drawable.light_send); 
newItem.setBackgroundDrawable(img); 

私は非常に悪い描かれた矢印を得ている、と私は上の青の背景を作成する問題を抱えていますダウン。何か不足していますか?

答えて

2

ImageButtonの場合は、背景色をcolor state listに設定します。あなたがしたい画像はsetImageResourceで、setBackgroundDrawableではありません。そうすれば、ScaleTypeを変更して、イメージの描画方法を調整することができます。私はcenter_insideを使って、見栄えの良い矢を手に入れます。 ImageButtonでは、バックグラウンドはどのビューでも同じように動作し、イメージリソースはコンテンツで背景の上に描画されます。