mirror of
https://github.com/samsonjs/media.git
synced 2026-03-27 09:45:47 +00:00
Support crop mode for AspectRatioFrameLayout
This commit is contained in:
parent
1829d71d29
commit
f764fe70b0
1 changed files with 21 additions and 1 deletions
|
|
@ -32,7 +32,7 @@ public final class AspectRatioFrameLayout extends FrameLayout {
|
|||
* Resize modes for {@link AspectRatioFrameLayout}.
|
||||
*/
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({RESIZE_MODE_FIT, RESIZE_MODE_FIXED_WIDTH, RESIZE_MODE_FIXED_HEIGHT, RESIZE_MODE_FILL})
|
||||
@IntDef({RESIZE_MODE_FIT, RESIZE_MODE_FIXED_WIDTH, RESIZE_MODE_FIXED_HEIGHT, RESIZE_MODE_FILL, RESIZE_MODE_CROP})
|
||||
public @interface ResizeMode {}
|
||||
|
||||
/**
|
||||
|
|
@ -51,6 +51,10 @@ public final class AspectRatioFrameLayout extends FrameLayout {
|
|||
* The specified aspect ratio is ignored.
|
||||
*/
|
||||
public static final int RESIZE_MODE_FILL = 3;
|
||||
/**
|
||||
* The height or width is increased or decreased to crop and to obtain the desired aspect ratio.
|
||||
*/
|
||||
public static final int RESIZE_MODE_CROP = 4;
|
||||
|
||||
/**
|
||||
* The {@link FrameLayout} will not resize itself if the fractional difference between its natural
|
||||
|
|
@ -96,6 +100,15 @@ public final class AspectRatioFrameLayout extends FrameLayout {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the resize mode.
|
||||
*
|
||||
* @return The resize mode.
|
||||
*/
|
||||
public int getResizeMode() {
|
||||
return this.resizeMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the resize mode.
|
||||
*
|
||||
|
|
@ -132,6 +145,13 @@ public final class AspectRatioFrameLayout extends FrameLayout {
|
|||
case RESIZE_MODE_FIXED_HEIGHT:
|
||||
width = (int) (height * videoAspectRatio);
|
||||
break;
|
||||
case RESIZE_MODE_CROP:
|
||||
if (videoAspectRatio > viewAspectRatio) {
|
||||
width = (int) (height * videoAspectRatio);
|
||||
} else {
|
||||
height = (int) (width / videoAspectRatio);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (aspectDeformation > 0) {
|
||||
height = (int) (width / videoAspectRatio);
|
||||
|
|
|
|||
Loading…
Reference in a new issue