2017-08-14 57 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