ListView组件中子项item的图标排列

前言
在设计ListView的Item项布局时,一开始使用LinearLayout布局,打算采用属性android:layout_gravity=”rigth”达到让图标处于一行中最右边的效果,但是并没有达到预期。后来改用RelativeLayout布局轻松达到预期效果。

效果图
这里写图片描述

源代码

-system_setting_item.xml

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

    <ImageView
        android:id="@+id/image_id"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_alignParentLeft="true"
        android:layout_margin="10dp"/>

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/image_id"
        android:layout_centerVertical="true"
        android:layout_marginLeft="10dp"/>

    <ImageView android:id="@+id/enter_id"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_alignParentRight="true"
        android:layout_margin="10dp"/>

</RelativeLayout>

猜你喜欢

转载自blog.csdn.net/dmw2016/article/details/79914981