Android 有没有办法将TextView垂直居中与RelativeLayout中的ImageView对齐

Android 有没有办法将TextView垂直居中与RelativeLayout中的ImageView对齐,android,android-layout,Android,Android Layout,我有一个RelativeLayout,左边是ImageView和TextView,右边是ImageView和TextView 但它们与ImageView不太一致。我希望它与文本视图旁边的图像垂直居中对齐 目前情况是这样的: 我使用的RelativeLayout是: 问题: 如何使TextView与ImageView很好地对齐 你说的对齐好是什么意思?你到底想实现什么?你试过android:layout_centerVertical=true吗?我假设你希望图像与文本的基线对齐,而不是与文本视图的

我有一个RelativeLayout,左边是ImageView和TextView,右边是ImageView和TextView

但它们与ImageView不太一致。我希望它与文本视图旁边的图像垂直居中对齐

目前情况是这样的:

我使用的RelativeLayout是:

问题:

如何使TextView与ImageView很好地对齐


你说的对齐好是什么意思?你到底想实现什么?你试过android:layout_centerVertical=true吗?我假设你希望图像与文本的基线对齐,而不是与文本视图的底部对齐。android:layout\u alignBaseline可能就是您要找的。@Farhadfaghi我正在尝试将TextView垂直居中对齐到旁边的图像it@birdy:您是否尝试过两个ImageView和两个TextView的android:layout_centerVertical=true?他们都需要有这个属性。我可以知道-1是的-你发布的任何东西都以什么方式解决了与TextViews中心对齐的问题吗?阅读问题标题。不,看起来不太好。首先,你似乎已经决定OP想要ic_发射器作为他们的可拖拉装置,而不是垃圾拖拉装置。您已将android:layout\u alignParentTop=true属性添加到第二个ImageView,但不是第一个,然后已将android:layout\u centerVertical=true添加到第二个TextView,但不是第一个。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="15dp"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="10dp"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/leftIcon"
        android:layout_alignParentLeft="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/trash" />

    <TextView
        android:id="@+id/tv1"
        android:layout_toRightOf="@+id/leftIcon"
        android:layout_toLeftOf="@+id/iv2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="14dp"
        android:text="some text 1"
        android:layout_marginLeft="5dp"
        android:textColor="#000000"
        android:textStyle="bold"/>

    <ImageView
        android:id="@+id/iv2"
        android:layout_toLeftOf="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/trash" />

    <TextView
        android:layout_alignParentRight="true"
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="14dp"
        android:textColor="#000000"
        android:text="some text 2"
        android:textStyle="bold"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="25dp" />
</RelativeLayout>
  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="15dp"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="10dp"
    android:orientation="horizontal"

    >

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

    <ImageView
        android:id="@+id/iv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/tv2"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/tv1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tv2"
        android:layout_toRightOf="@+id/leftIcon"
        android:text="some text 1"
        android:textColor="#000000"
        android:textSize="14dp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="26dp"
        android:text="some text 2"
        android:textColor="#000000"
        android:textSize="14dp"
        android:textStyle="bold" />

</RelativeLayout>
hi try this code i think it will help you : 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="15dp"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:layout_alignParentLeft="true"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/leftIcon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@android:drawable/ic_menu_delete" />

        <TextView
            android:id="@+id/tv1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text="some text 1"
            android:textColor="#ffffff"
            android:textSize="14dp"
            android:textStyle="bold" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:gravity="center_vertical"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/iv2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@android:drawable/ic_menu_delete" />

        <TextView
            android:id="@+id/tv2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="25dp"
            android:text="some text 2"
            android:textColor="#ffffff"
            android:textSize="14dp"
            android:textStyle="bold" />

    </LinearLayout>

</RelativeLayout>
// Try this way,hope this will help you to solve your problem...

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center">
        <ImageView
            android:id="@+id/leftIcon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher"
            android:adjustViewBounds="true"/>

        <TextView
            android:id="@+id/tv1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="14sp"
            android:text="some text 1"
            android:layout_marginLeft="5dp"
            android:textColor="#000000"
            android:textStyle="bold"/>

        </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center_vertical|right">
        <ImageView
            android:id="@+id/iv2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher"
            android:adjustViewBounds="true"/>

        <TextView
            android:id="@+id/tv2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="14sp"
            android:textColor="#000000"
            android:text="some text 2"
            android:textStyle="bold"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="25dp" />
    </LinearLayout>
</LinearLayout>