Android: Keep ratio for a full-width and undefined height ImageView in a ConstraintLayout?

前端 未结 2 1007
灰色年华
灰色年华 2021-01-24 08:01

In a ConstraintLayout, an ImageView is bound to its parent in such a way that:

  1. Its left side is bound to the screen\'s left side

相关标签:
2条回答
  • 2021-01-24 08:11

    In addition to the last answer, the reason your image is not being scaled properly is because you are using it as the background.

    Your code..

    android:background="@drawable/ic_background_stars"
    

    Instead, use it as image resource.

    app:srcCompat="@drawable/ic_background_stars"
    

    And the default scale type of ImageView should do the work for you. Else, you can even experiment with various scale types.

    0 讨论(0)
  • 2021-01-24 08:12

    I think that you can use app:layout_constraintDimensionRatio="your ratio" to keep the aspect ratio if your image

    For example, if you want square you need the same width and height so use - app:layout_constraintDimensionRatio="1:1"

    0 讨论(0)
提交回复
热议问题