@@ -39,43 +39,34 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
3939 int heightSpecSize = MeasureSpec .getSize (heightMeasureSpec );
4040
4141 if (widthSpecMode == MeasureSpec .EXACTLY && heightSpecMode == MeasureSpec .EXACTLY ) {
42- // the size is fixed
4342 width = widthSpecSize ;
4443 height = heightSpecSize ;
4544
46- // for compatibility, we adjust size based on aspect ratio
4745 if (videoWidth * height < width * videoHeight ) {
4846 width = height * videoWidth / videoHeight ;
4947 } else if (videoWidth * height > width * videoHeight ) {
5048 height = width * videoHeight / videoWidth ;
5149 }
5250 } else if (widthSpecMode == MeasureSpec .EXACTLY ) {
53- // only the width is fixed, adjust the height to match aspect ratio if possible
5451 width = widthSpecSize ;
5552 height = width * videoHeight / videoWidth ;
5653 if (heightSpecMode == MeasureSpec .AT_MOST && height > heightSpecSize ) {
57- // couldn't match aspect ratio within the constraints
5854 height = heightSpecSize ;
5955 }
6056 } else if (heightSpecMode == MeasureSpec .EXACTLY ) {
61- // only the height is fixed, adjust the width to match aspect ratio if possible
6257 height = heightSpecSize ;
6358 width = height * videoWidth / videoHeight ;
6459 if (widthSpecMode == MeasureSpec .AT_MOST && width > widthSpecSize ) {
65- // couldn't match aspect ratio within the constraints
6660 width = widthSpecSize ;
6761 }
6862 } else {
69- // neither the width nor the height are fixed, try to use actual video size
7063 width = videoWidth ;
7164 height = videoHeight ;
7265 if (heightSpecMode == MeasureSpec .AT_MOST && height > heightSpecSize ) {
73- // too tall, decrease both width and height
7466 height = heightSpecSize ;
7567 width = height * videoWidth / videoHeight ;
7668 }
7769 if (widthSpecMode == MeasureSpec .AT_MOST && width > widthSpecSize ) {
78- // too wide, decrease both width and height
7970 width = widthSpecSize ;
8071 height = width * videoHeight / videoWidth ;
8172 }
@@ -85,25 +76,24 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
8576 }
8677
8778 if (getRotation () != 0 && getRotation () % 90 == 0 ) {
88- if (widthS < heightS ) {//旋转了90度,其实是竖的,适配宽度
89- if (width > height ) {//竖版的视频
79+ if (widthS < heightS ) {
80+ if (width > height ) {
9081 width = (int ) (width * (float ) widthS / height );
9182 height = widthS ;
92- } else {//横版的视频
83+ } else {
9384 height = (int ) (height * (float ) width / widthS );
9485 width = widthS ;
9586 }
96- } else {//旋转了90度,其实是横的,适配高度
97- if (width > height ) {//竖版的视频
87+ } else {
88+ if (width > height ) {
9889 height = (int ) (height * (float ) width / widthS );
9990 width = widthS ;
100- } else {//横版的视频
91+ } else {
10192 width = (int ) (width * (float ) widthS / height );
10293 height = widthS ;
10394 }
10495 }
10596 }
106- //Log.e("back", "width " + width + " height " + height);
10797 setMeasuredDimension (width , height );
10898 }
10999}
0 commit comments