mam do czynienia z pozornie prostym zadaniem ma układ z:ConstraintLayout: miejsce TextView poniżej ImageView
- An
ImageView
biorąc pełną szerokość, wysokość zgodnie z proporcjami obrazka TextView
niższym niż
to co mam
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/hamster"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText MyText "
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/image_view"/>
</android.support.constraint.ConstraintLayout>
I to właśnie wygląda:
Jak widać, ImageView
ma margines do góry, które nie chcę.
Gdybym zmienić ImageView's
ograniczeń z
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
do
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
(usuwanie dolne ograniczenie), wynik wygląda tak:
Teraz ImageView
jest o godz e bardzo na szczycie mojego układu, ale odszedł TextView
. Przeszkadza Ci, dla drugiego wariantu, podgląd układ Android Studio 3 pokazuje układ dokładnie jak bym go chciał:
Co robię źle i jak mogę to naprawić?
Uwaga: Układ musi być w formacie ConstraintLayout
, a wysokość układu musi wynosić wrap_content
.
Możesz znaleźć mój projekt testowy here.
EDYCJA: Problem wydaje się występować tylko na większych urządzeniach. Używam emulatora Nexus 9.
Próbowałaś użyciem 'aplikacji: layout_constraintVertical_bias = 0.0' –
@Ascorbin, praca nirva szacha roztworu użytkowego ?? –
@ShwetaChauhan Nope, zobacz mój komentarz poniżej jego odpowiedzi. – FWeigl