简体   繁体   中英

Android: Retain Aspect Ratio for ImageView set as Background

I have a rectangle View and a square ImageView. I want to set the background of the View to the ImageView.getDrawable, but I want to retain the aspect ratio.

myView.setBackground(myImageView.getDrawable()

Currently this stretches the square image to the rectangle shape.

How would I do something similar but retain the aspect ratio of the square image inside of the rectangle view?

You don't use background to do that- background always stretches to fill. If you want to do this use two image views on top of each other. You may also need to mutate the original drawable and pass the mutation into the second view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM