开发者

Why two items in the same relative layout are differently layouted?

开发者 https://www.devze.com 2023-03-10 11:41 出处:网络
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

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 f开发者_C百科irst 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>

Why two items in the same relative layout are differently layouted?


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.


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.

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号