2017-04-27 126 views
1

我在使ImageView垂直填充剩餘空隙時遇到了一些小問題。我在屏幕截圖上用紅色突出顯示了它。有人可以看看並提供一些建議嗎?拉伸ImageView垂直約束佈局

https://i.stack.imgur.com/PBio1.png

這是相關的XML代碼:

<?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.android.happybirthday.MainActivity"> 

<ImageView 
    android:id="@+id/imageView" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:adjustViewBounds="true" 
    android:contentDescription="@string/happy_birthday_toyou" 
    android:scaleType="centerCrop" 
    android:src="@drawable/invite" 
    app:layout_constraintBottom_toTopOf="@+id/textViewBottom" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toBottomOf="@+id/textViewTop" /> 

<TextView 
    android:id="@+id/textViewTop" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:padding="8dp" 
    android:fontFamily="sans-serif" 
    android:text="@string/happy_birthday_toyou" 
    android:textColor="@color/colorWhite" 
    android:background="@color/colorBlack" 
    android:textSize="@dimen/text_size" 
    android:gravity="start" 
    app:layout_constraintEnd_toEndOf="parent" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintStart_toStartOf="parent" 
    /> 

<TextView 
    android:id="@+id/textViewBottom" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:background="@color/colorBlack" 
    android:fontFamily="sans-serif" 
    android:gravity="end" 
    android:padding="8dp" 
    android:text="@string/from_me" 
    android:textColor="@color/colorWhite" 
    android:textSize="@dimen/text_size" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintStart_toStartOf="parent" 
    /> 



</android.support.constraint.ConstraintLayout> 

回答

2

嘗試改變:在您的ImageView的 「機器人layout_height =」 WRAP_CONTENT」到0dp

+0

我發誓我這昨天試過了,它不會工作,現在試用它可以正常工作:) – davemib123

+0

Android是一個充滿魔力的世界,永遠記住使用適當的約束條件,當試圖使你的視圖填充佈局時,它們可能會非常棘手。 –