2010-08-19 1 views
0

Android 애플리케이션의 모든 ListView 항목 텍스트 앞에 아이콘을 추가하려면 어떻게해야합니까?안드로이드 응용 프로그램의 모든 ListView 항목 텍스트 앞에 아이콘을 추가하는 방법은 무엇입니까?

는 여기에 목록을 채우는라고 현재 LIST_ITEM의 XML입니다 :

<?xml version="1.0" encoding="utf-8"?> 


<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:gravity="center_vertical" 
    android:padding="5dip" 
    android:background="@color/darkblue" 
/> 

내가 그것을하기 전에 이미지 뷰를 추가하려고 시도했지만 전혀 보이지 않았다. 그런 다음 RelativeLayout을 전체 주위에 추가하고 배치를 시도했지만 여전히 표시되지 않았습니다.

아이디어가 있으십니까?

감사합니다.

+0

RelativeLay 대신의 LinearLayout을보십시오 아웃. –

답변

1

더 나은 방법을 layout_toRightOf을, drawableBottom 태그 :

<?xml version="1.0" encoding="utf-8"?> 


<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:gravity="center_vertical" 
    android:padding="5dip" 
    android:background="@color/darkblue" 
    android:drawableLeft="@drawable/yourPicture" 

/> 
2

당신은 단지 속성 안드로이드 추가, 상대 레이아웃을 사용할 수 있습니다 : 당신의 텍스트 뷰 ::에이 drawableLeft, drawableRight, drawableTop을 사용하는 것입니다 할

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal"> 
<ImageView 
     android:id="@+id/myIcon" 
     android:layout_width="25px" 
     android:layout_height="25px"  
     android:layout_alignParentTop="true" 
     android:layout_alignParentBottom="true" 
     android:layout_centerVertical="true" 
     android:focusable="false" 
     android:padding="4px" 
     /> 
<TextView 
    android:id="@android:id/text1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:gravity="center_vertical" 
    android:padding="5dip" 
    android:background="@color/darkblue" 
android:layout_toRightOf="@id/myIcon" 
/> 

</RelativeLayout> 
+0

'TextView'에서'xmlns : android'를 "복사/붙여 넣기"실수로 설정하지 않았습니까? – Izydorr

+0

upsss! 너는 맞다. 아이 도어, 고마워. =) – Jorgesys

관련 문제