2017-08-14 61 views
1
我使用的是RecyclerView

,这是activity_main代码:的ImageView与TextView的重叠ConstraintLayout

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.romin.apodbrowser.MainActivity"> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/recyclerView" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="8dp" 
    android:layout_marginLeft="8dp" 
    android:layout_marginRight="8dp" 
    android:layout_marginTop="8dp" 
    android:scrollbars="vertical" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintHorizontal_bias="0.0" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent" /> 
</android.support.constraint.ConstraintLayout> 

而对于这个RecyclerView项目是布局:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/list_item" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical"> 

<org.sufficientlysecure.htmltextview.HtmlTextView 
    android:id="@+id/title" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginEnd="8dp" 
    android:layout_marginLeft="8dp" 
    android:layout_marginRight="8dp" 
    android:layout_marginStart="8dp" 
    android:text="TextView" 
    android:textSize="24sp" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    tools:layout_editor_absoluteY="16dp" /> 

<TextView 
    android:id="@+id/pubDate" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginEnd="8dp" 
    android:layout_marginLeft="8dp" 
    android:layout_marginRight="8dp" 
    android:layout_marginStart="8dp" 
    android:layout_marginTop="8dp" 
    android:text="TextView" 
    android:textAppearance="@style/TextAppearance.AppCompat" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toBottomOf="@+id/link" /> 

<ImageView 
    android:id="@+id/image" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_marginEnd="8dp" 
    android:layout_marginLeft="8dp" 
    android:layout_marginRight="8dp" 
    android:layout_marginStart="8dp" 
    android:layout_marginTop="8dp" 
    android:adjustViewBounds="true" 
    android:scaleType="fitStart" 
    app:layout_constraintHorizontal_bias="0.0" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toBottomOf="@+id/pubDate" 
    app:srcCompat="@drawable/default_image" /> 


<org.sufficientlysecure.htmltextview.HtmlTextView 
    android:id="@+id/description" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/image" 
    android:layout_marginBottom="8dp" 
    android:layout_marginEnd="8dp" 
    android:layout_marginLeft="8dp" 
    android:layout_marginRight="8dp" 
    android:layout_marginStart="8dp" 
    android:layout_marginTop="8dp" 
    android:text="TextView" 
    android:textSize="16sp" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintHorizontal_bias="0.0" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toBottomOf="@+id/image" 
    tools:text="Description" /> 

<TextView 
    android:id="@+id/link" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginEnd="8dp" 
    android:layout_marginLeft="8dp" 
    android:layout_marginRight="8dp" 
    android:layout_marginStart="8dp" 
    android:layout_marginTop="8dp" 
    android:text="TextView" 
    android:textSize="16sp" 
    app:layout_constraintHorizontal_bias="1.0" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toBottomOf="@+id/title" 
    tools:text="LINK" /> 
</android.support.constraint.ConstraintLayout> 

本质上说,顶部的标题,链接和pubDate。然后是图像,然后是描述。除了图像(ImageView)之外,其他的都是TextViews。

问题是,当我从RSS提要将图像加载到ImageView并且缩略图消失时,ImageView与描述TextView重叠。我到处搜索,但我似乎无法找到任何解决方案。我知道位图改变了它的大小,而不是ImageView,最有可能是导致重叠的原因,但我找不到解决它的方法。

非常感谢你提前。

截图:

[https://i.stack.imgur.com/e2eMA.jpg][1]

+0

你可以发布图像有一个想法如何和它在哪里重叠? –

+0

@AalapPatel我编辑了这个问题,在最后加入了截图。谢谢! – hms

回答

0

description删除下面的行:

app:layout_constraintBottom_toBottomOf="parent" 

这将有效地移动图像以下的说明图。我刚刚测试过,它正在工作。

我希望这会有所帮助。

+0

我试过你的解决方案,但图像现在似乎没有调整视图边界。它的位置不在中间,距离左边和右边的距离相等,尽管我将scaleType设置为fitStart并将adjustBounds设置为true。 – hms

+0

@hms我误读了XML。我会再尝试。您的描述受限于父级的底部和图像的底部。图像是否如此高,以至于它与说明重叠,因为说明没有将图像和父图像之间的距离挤压到哪里?如果是这样的话,你想要发生什么?你可以张贴截图使事情更清楚吗? – Cheticamp

+0

@hms查看更新的答案。 – Cheticamp