Bildansicht Skalierung Problem in ConstriantLayout

stimmen
0

Ich verwende eine Imageview in einem Constraint-Layout und mag die Breite des Image Bildschirm Breite und Höhe zu sein, dynamisch sein nach Bild.

Meine XML für das Layout ist

<?xml version=1.0 encoding=utf-8?>
<android.support.v7.widget.CardView 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
style=@style/CardView.Light
android:layout_width=match_parent
android:layout_height=wrap_content
android:layout_marginTop=8dp>

<android.support.constraint.ConstraintLayout
    android:layout_width=match_parent
    android:layout_height=wrap_content
    android:background=@color/newsItemBackground
    tools:layout_editor_absoluteY=29dp>

    <TextView
        android:id=@ id/textTitle
        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:textColor=@color/textHighEmphasis
        android:textSize=@dimen/news_title_size
        android:textStyle=bold
        app:layout_constraintEnd_toEndOf=parent
        app:layout_constraintStart_toStartOf=parent
        app:layout_constraintTop_toTopOf=parent
        tools:text=Title />

    <TextView
        android:id=@ id/textTime
        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:fontFamily=@font/english_font
        android:textColor=@color/textMediumEmphasis
        android:textSize=@dimen/news_time_size
        android:textStyle=normal
        app:layout_constraintEnd_toEndOf=parent
        app:layout_constraintStart_toStartOf=parent
        app:layout_constraintTop_toBottomOf=@ id/textTitle
        tools:text=Time />

    <Button
        android:id=@ id/buttonMore
        style=@style/Widget.AppCompat.Button.Borderless.Colored
        android:layout_width=wrap_content
        android:layout_height=wrap_content
        android:layout_marginEnd=8dp
        android:layout_marginRight=8dp
        app:layout_constraintBottom_toBottomOf=parent
        app:layout_constraintEnd_toStartOf=@ id/buttonShare
        app:layout_constraintTop_toBottomOf=@ id/viewSeperator
        app:layout_constraintVertical_bias=0.0
        tools:text=readmore />

    <Button
        android:id=@ id/buttonShare
        style=@style/Widget.AppCompat.Button.Borderless.Colored
        android:layout_width=wrap_content
        android:layout_height=wrap_content
        android:layout_marginEnd=8dp
        android:layout_marginRight=8dp
        android:text=@string/share_button
        app:layout_constraintBottom_toBottomOf=parent
        app:layout_constraintEnd_toEndOf=parent
        app:layout_constraintTop_toBottomOf=@ id/viewSeperator
        app:layout_constraintVertical_bias=0.0 />


    <TextView
        android:id=@ id/textBody
        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:textColor=@color/textHighEmphasis
        android:textSize=@dimen/news_body_size
        android:textStyle=normal
        app:layout_constraintEnd_toEndOf=parent
        app:layout_constraintHorizontal_bias=0.0
        app:layout_constraintStart_toStartOf=parent
        app:layout_constraintTop_toBottomOf=@ id/imageNews
        tools:text=Body />


    <View
        android:id=@ id/viewSeperator
        android:layout_width=0dp
        android:layout_height=1px
        android:layout_marginEnd=8dp
        android:layout_marginLeft=8dp
        android:layout_marginRight=8dp
        android:layout_marginStart=8dp
        android:layout_marginTop=8dp
        android:background=@color/cardSeperatorLine
        app:layout_constraintEnd_toEndOf=parent
        app:layout_constraintStart_toStartOf=parent
        app:layout_constraintTop_toBottomOf=@ id/textBody />

    <ImageView
        android:id=@ id/imageNews
        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:scaleType=centerCrop
        app:layout_constraintEnd_toEndOf=parent
        app:layout_constraintHorizontal_bias=0.0
        app:layout_constraintStart_toStartOf=parent
        app:layout_constraintTop_toBottomOf=@ id/textTime
        app:srcCompat=@drawable/portait_man />


</android.support.constraint.ConstraintLayout>

</android.support.v7.widget.CardView>

Dieses Bild sieht gut aus in Editor android Studios jedoch, wenn ich es laden Glide verwenden, wird das Bild der Höhe von oben und unten abgeschnitten.

Bild von Editor

Editor

Bild während der Ausführung der App

Live-Bild

Ich lade den Code mit

Glide.with(imageNews.getContext())
                .load(item.image_url)
                .into(imageNews);
Veröffentlicht am 02/09/2018 um 05:23
quelle vom benutzer
In anderen Sprachen...                            


3 antworten

stimmen
0

gerade gesetzt

android:adjustViewBounds="true"

und es wird funktionieren

Beantwortet am 02/09/2018 um 06:05
quelle vom benutzer

stimmen
0

versuchen Sie unter

<android.support.v7.widget.CardView 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="wrap_content"
    android:layout_marginTop="8dp">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@ id/textTitle"
            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:textStyle="bold"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:text="Title" />

        <TextView
            android:id="@ id/textTime"
            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:textStyle="normal"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@ id/textTitle"
            tools:text="Time" />

        <Button
            android:id="@ id/buttonMore"
            style="@style/Widget.AppCompat.Button.Borderless.Colored"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@ id/buttonShare"
            app:layout_constraintTop_toBottomOf="@ id/viewSeperator"
            app:layout_constraintVertical_bias="0.0"
            tools:text="readmore" />

        <Button
            android:id="@ id/buttonShare"
            style="@style/Widget.AppCompat.Button.Borderless.Colored"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            android:text="share_button"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@ id/viewSeperator"
            app:layout_constraintVertical_bias="0.0" />


        <TextView
            android:id="@ id/textBody"
            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:textStyle="normal"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@ id/imageNews"
            tools:text="Body" />


        <View
            android:id="@ id/viewSeperator"
            android:layout_width="0dp"
            android:layout_height="1px"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@ id/textBody" />

        <ImageView
            android:id="@ id/imageNews"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@ id/textTime"
            app:srcCompat="@mipmap/ic_logo" />


    </android.support.constraint.ConstraintLayout>

</android.support.v7.widget.CardView>

Stellen Sie sicher, temporäre ich habe entfernen Sie einfach Ihren Farbcode und Text von String.

Beantwortet am 02/09/2018 um 05:32
quelle vom benutzer

stimmen
0

Beachten Sie, dass centerCropdas Bild ein wenig etwas vergrößern. Wenn Sie das wollen , ImageViewflexibel sein auf der Grundlage der Resolution Entfernen des Bildes , scaleTypeaber dies zu unerwartetem Verhalten führen kann.

<ImageView
        android:id="@ id/imageNews"
        android:layout_width="wrap_content" // Changed to wrap_content
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:scaleType="centerCrop"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@ id/textTime"
        app:srcCompat="@drawable/portait_man" />
Beantwortet am 02/09/2018 um 05:28
quelle vom benutzer

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more