Android 为什么相同相对布局中的两个项目的布局不同?

Android 为什么相同相对布局中的两个项目的布局不同?,android,android-relativelayout,Android,Android Relativelayout,我有一个列表视图,其项由RelativeLayout指定 有一个图像(灰色箭头,这是png,带有透明填充)。在第一种情况下,蓝色背景的文本与该图像重叠,在第二种情况下,它是对齐的。 这些情况之间的唯一区别是,在第一种情况下,左照片是不可见的。我不明白为什么在第二种情况下,蓝色文本不与灰色箭头重叠?(这是可取的行为) 我以前从未使用过Android编码,但只要看看你的代码,我就会说,Android:layout\u alignParentRight=“true”之间存在冲突,可以在这里找到:

我有一个列表视图,其项由RelativeLayout指定

有一个图像(灰色箭头,这是png,带有透明填充)。在第一种情况下,蓝色背景的文本与该图像重叠,在第二种情况下,它是对齐的。 这些情况之间的唯一区别是,在第一种情况下,左照片是不可见的。我不明白为什么在第二种情况下,蓝色文本不与灰色箭头重叠?(这是可取的行为)



我以前从未使用过Android编码,但只要看看你的代码,我就会说,Android:layout\u alignParentRight=“true”之间存在冲突,可以在这里找到:

<ImageView
    android:id="@+id/dis_ind"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:src="@drawable/dis_ind"/> 
  <TextView
    android:id="@+id/description"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/separator"
    android:layout_below="@id/title"
    android:layout_alignParentBottom="true"
    android:textColor="@color/article_text_secondary"
    android:maxLines="4"
    android:background="#F00F"/>

我以前从未使用过代码库,也没有为您提供“解决方案”,但它可能会为您提供一个起点。

由于图片不再存在于俯视图中,因此布局变得更小,因此文本视图更接近。在两个文本视图之间留出一些空白以解决问题。

通过提取线性布局并将照片移动到其中解决了问题。出于某种原因,这张照片在相同的布局中包含了文本之间的空间

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="@dimen/padding_content">
    <ru.ip_news.ui.views.RationalImage
        android:id="@+id/picture"
        android:layout_width="@dimen/article_short_image_width"
        android:layout_height="fill_parent"/>
    <RelativeLayout   
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:paddingLeft="@dimen/padding_content">
      <ImageView
        android:id="@+id/dis_ind"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:src="@drawable/dis_ind"/>   
      <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/dis_ind"
        android:layout_gravity="left"
        android:layout_alignParentLeft="true"
        android:textStyle="bold"
        android:textColor="@color/article_text_main"
        android:maxLines="2"
        android:ellipsize="end"/>
      <TextView
        android:id="@+id/description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/title"
        android:layout_alignParentBottom="true"
        android:textColor="@color/article_text_secondary"
        android:maxLines="4"/>
    </RelativeLayout>
</LinearLayout>

请注意,第一种情况是可取的。因此,增加利润是行不通的。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="@dimen/padding_content">
    <ru.ip_news.ui.views.RationalImage
        android:id="@+id/picture"
        android:layout_width="@dimen/article_short_image_width"
        android:layout_height="fill_parent"/>
    <RelativeLayout   
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:paddingLeft="@dimen/padding_content">
      <ImageView
        android:id="@+id/dis_ind"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:src="@drawable/dis_ind"/>   
      <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/dis_ind"
        android:layout_gravity="left"
        android:layout_alignParentLeft="true"
        android:textStyle="bold"
        android:textColor="@color/article_text_main"
        android:maxLines="2"
        android:ellipsize="end"/>
      <TextView
        android:id="@+id/description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/title"
        android:layout_alignParentBottom="true"
        android:textColor="@color/article_text_secondary"
        android:maxLines="4"/>
    </RelativeLayout>
</LinearLayout>