Android 对齐表格行上的图标

Android 对齐表格行上的图标,android,icons,alignment,tablerow,Android,Icons,Alignment,Tablerow,您好,我在对齐2个图标和图标中心的文本视图时遇到问题。 实际上,第一个图标和文本正确对齐,但最后一个图标“playIcon”没有对齐。我希望他在右角。。全部对齐。 这就是我所拥有的 -- 这是我的XML 您可以使用RelativeLayout来对齐左右图像。 类似于以下代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/

您好,我在对齐2个图标和图标中心的文本视图时遇到问题。 实际上,第一个图标和文本正确对齐,但最后一个图标“playIcon”没有对齐。我希望他在右角。。全部对齐。 这就是我所拥有的

--

这是我的XML
您可以使用RelativeLayout来对齐左右图像。 类似于以下代码:

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:contentDescription="TODO"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/txt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_toRightOf="@id/img"
        android:layout_toLeftOf="@id/img2"
        android:gravity="center"
        android:text="Test"/>

    <ImageView
        android:id="@+id/img2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:contentDescription="TODO"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>

使用android:layout\u alignParentLeft=“true”表示左侧图像,使用android:layout\u alignParentRight=“true”表示右侧图像。也可以对这两个应用程序使用android:layout\u centerVertical=“true”

我希望这段代码会有用

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:contentDescription="TODO"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/txt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_toRightOf="@id/img"
        android:layout_toLeftOf="@id/img2"
        android:gravity="center"
        android:text="Test"/>

    <ImageView
        android:id="@+id/img2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:contentDescription="TODO"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>