2013-11-25 3 views
0

Как я могу выровнять значок в ImageView в моем ListView? Я попробовал гравитацию = «правильно», но это не сработало. Нужно ли добавлять linerlayout специально для этого? Спасибо за вашу помощь. Ниже мой код:Как выровнять правую иконку в моем ListItem

enter image description here

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="?android:attr/listPreferredItemHeight" 
    android:gravity="center_vertical" 
    android:paddingRight="?android:attr/scrollbarSize"> 

    <ImageView 
     android:id="@+id/list_item_entry_drawable" 
     android:layout_width="50dip" 
     android:layout_height="50dip" 
     android:gravity="right" 
     android:src="@android:drawable/ic_menu_preferences" 
     android:paddingLeft="9dp"/> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dip" 
     android:layout_marginRight="6dip" 
     android:layout_marginTop="6dip" 
     android:layout_marginBottom="6dip" 
     android:layout_weight="1"> 

     <TextView android:id="@+id/list_item_entry_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:singleLine="true" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:ellipsize="marquee" 
      android:fadingEdge="horizontal" /> 

     <TextView android:id="@+id/list_item_entry_summary" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/list_item_entry_title" 
      android:layout_alignLeft="@id/list_item_entry_title" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:singleLine="true" 
      android:textColor="?android:attr/textColorSecondary" /> 

    </RelativeLayout> 

</LinearLayout> 

ответ

0

Вы должны положить ImageView в RelativeLayout и использовать код ниже:

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_centerVertical="true" 
    android:src="@drawable/your_icon" /> 

Надеется, что это полезно.

Смежные вопросы