簡體   English   中英

圖像視圖在約束布局中移動到左側

[英]Image View moving to left side in constraint Layout

我創建了一個布局,其中 ImageView 被限制在屏幕的四個邊緣布局圖像 但是當我運行應用程序時,ImageView 會向左移動活動截圖

我無法找出問題所在

我也提供了 xml 布局文件。 我想將圖像視圖設置在屏幕的中心。 我只是提供布局的圖像視圖部分。

XML布局

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="match_parent"
    android:background="@color/semiTransparent">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:contentDescription="@string/image_of_the_song"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.3"
        app:srcCompat="@android:drawable/divider_horizontal_bright" />


</androidx.constraintlayout.widget.ConstraintLayout>

您的問題是無法滿足約束,您正在設置 imageview 的寬度和高度,同時還試圖水平約束它。

改變這個

<ImageView
    android:id="@+id/imageView"
    android:layout_width="250dp"
    android:layout_height="250dp"
    android:contentDescription="@string/image_of_the_song"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.3"
    app:srcCompat="@android:drawable/divider_horizontal_bright" />

對此

<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="250dp"
    android:adjustViewBounds="true"
    android:contentDescription="@string/image_of_the_song"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.3"
    app:srcCompat="@android:drawable/divider_horizontal_bright" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM