2013-02-06 12 views
5

drawableLeftまたはsetCompundDrawablesを使用して、textviewの複合ドロアブルを設定できますが、これを使用してdrawableを左/右/上/下に配置することができます。テキストビューの左上および右上にのみドロアブルを配置します。 どうすればいいですか?Compound ViewをText Viewの左上に配置する方法

+0

すでに尋ねられました[こちら](http://stackoverflow.com/questions/10267352/align-top-of-image-to-top-of-textview) – minipif

答えて

4
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:src="@drawable/ic_launcher" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@+id/imageView1" 
    android:text="@string/text" /> 

これはそうです。

+3

textViewではなくrelativelayoutを使用する際のトレードオフは何ですか? ? –

1

私は、3つのビューよりも簡単で高速な方法があると思います。アイコンのために適切な9patchを準備し、FrameLayoutを使用する必要があります。 シングルEditText/TextViewだけをバックグラウンドと同じドロアブルで使用することもできます。詳細はthis answerに記載されています。

関連する問題