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

发布于 2024-11-12 06:27:12 字数 1892 浏览 2 评论 0原文

我有一个由RelativeLayout指定的项目的列表视图

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

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  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"/>
  <View
    android:id="@+id/separator"
    android:layout_width="@dimen/padding_content"
    android:layout_height="fill_parent"
    android:layout_toRightOf="@id/picture"/>
  <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_toRightOf="@id/separator"
    android:layout_toLeftOf="@id/dis_ind"
    android:layout_gravity="left"
    android:textStyle="bold"
    android:textColor="@color/article_text_main"
    android:maxLines="2"
    android:ellipsize="end"
    android:background="#F0F0"/>
  <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"/>
</RelativeLayout>

在此处输入图像描述

I have a listview with item specified by RelativeLayout

There is an image (gray arrow, this is png, with transparent padding). In first case text with blue back overlaps this image, in second - it is aligned.
The only difference between these cases is that left photo is invisible in first case. I do not understand why in second case the blue text does not overlap gray arrow? (it is desirable behavior)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  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"/>
  <View
    android:id="@+id/separator"
    android:layout_width="@dimen/padding_content"
    android:layout_height="fill_parent"
    android:layout_toRightOf="@id/picture"/>
  <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_toRightOf="@id/separator"
    android:layout_toLeftOf="@id/dis_ind"
    android:layout_gravity="left"
    android:textStyle="bold"
    android:textColor="@color/article_text_main"
    android:maxLines="2"
    android:ellipsize="end"
    android:background="#F0F0"/>
  <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"/>
</RelativeLayout>

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月下凄凉 2024-11-19 06:27:12

之间存在冲突

<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"/> 

我以前从未使用过 Android 编码,但仅通过查看您的代码,我会说此处找到的 android:layout_alignParentRight="true"与您的 android:layout_alignParentBottom 在这里找到:“true”

  <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"/>

我以前从未使用过代码库,也没有适合您的“解决方案”,但也许它会给您一个起点。

I've never worked with Android coding before, but just from looking at your code I'd say there's a conflict between android:layout_alignParentRight="true" found here:

<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"/> 

and your android:layout_alignParentBottom="true" found here:

  <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"/>

I've never worked with the code base before and don't have a "solution" for you, but maybe it'll get you a starting point.

下壹個目標 2024-11-19 06:27:12

由于顶视图中不再存在图片,因此布局变得更小,因此文本视图更接近。在两个文本视图之间放置一些边距来解决该问题。

Since the picture no longer exists in the top view , the layout has become smaller so the textviews are closer. Put some margin between the two text views to fix the issue.

娇俏 2024-11-19 06:27:12

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

<?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>

Resolved the problem by extracting linearlayout and moving photo to it. For some reason this photo in the same layout involves space between texts.

<?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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文