为什么相同相对布局中的两个项目的布局不同?
我有一个由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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
之间存在冲突
我以前从未使用过 Android 编码,但仅通过查看您的代码,我会说此处找到的
android:layout_alignParentRight="true"
与您的android:layout_alignParentBottom 在这里找到:“true”
:我以前从未使用过代码库,也没有适合您的“解决方案”,但也许它会给您一个起点。
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:and your
android:layout_alignParentBottom="true"
found here: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.
由于顶视图中不再存在图片,因此布局变得更小,因此文本视图更接近。在两个文本视图之间放置一些边距来解决该问题。
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.
通过提取线性布局并将照片移动到其中解决了该问题。由于某种原因,相同布局中的这张照片在文本之间存在空格。
Resolved the problem by extracting linearlayout and moving photo to it. For some reason this photo in the same layout involves space between texts.