「Android/VideoView/横幅に合わせて縦幅自動調節」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「==サンプル== ViewGroup.LayoutParams params = videoView.getLayoutParams(); double aspect = (double) videoView.getMediaFileWidth() / videoView.getMediaFileHeight();...」) |
|||
行1: | 行1: | ||
==サンプル== | ==サンプル== | ||
ViewGroup.LayoutParams params = videoView.getLayoutParams(); | ViewGroup.LayoutParams params = videoView.getLayoutParams(); | ||
− | double aspect = (double) | + | double aspect = (double) 500 / 400; |
Log.i(TAG, "aspect=" + aspect); | Log.i(TAG, "aspect=" + aspect); | ||
Log.i(TAG, "width=" + videoView.getWidth()); | Log.i(TAG, "width=" + videoView.getWidth()); | ||
int height = (int) (videoView.getWidth() / aspect); // getWidth()はonWindowFocusChanged実行後取得可能 | int height = (int) (videoView.getWidth() / aspect); // getWidth()はonWindowFocusChanged実行後取得可能 | ||
params.height = height; | params.height = height; | ||
+ | |||
+ | 横幅指定パターン | ||
+ | <VideoView android:id="@+id/videoView" android:layout_width="200dp" android:layout_height="wrap_content"> | ||
+ | </VideoView> | ||
+ | |||
+ | 横幅いっぱいパターン | ||
+ | <VideoView android:id="@+id/videoView" android:layout_width="match_parent" android:layout_height="wrap_content"> | ||
+ | </VideoView> |
2018年11月14日 (水) 19:05時点における最新版
サンプル
ViewGroup.LayoutParams params = videoView.getLayoutParams(); double aspect = (double) 500 / 400; Log.i(TAG, "aspect=" + aspect); Log.i(TAG, "width=" + videoView.getWidth()); int height = (int) (videoView.getWidth() / aspect); // getWidth()はonWindowFocusChanged実行後取得可能 params.height = height;
横幅指定パターン
<VideoView android:id="@+id/videoView" android:layout_width="200dp" android:layout_height="wrap_content"> </VideoView>
横幅いっぱいパターン
<VideoView android:id="@+id/videoView" android:layout_width="match_parent" android:layout_height="wrap_content"> </VideoView>