android居中显示,surfaceview居中显示

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

public void setVideoParams(MediaPlayer mediaPlayer, boolean isLand) {

//获取surfaceView父布局的参数

ViewGroup.LayoutParams rl_paramters = mRlVideo.getLayoutParams();

//获取SurfaceView的参数

ViewGroup.LayoutParams sv_paramters = mSvVideo.getLayoutParams();

//设置宽高比为16/9

float screen_widthPixels = getResources().getDisplayMetrics().widthPixels;

float screen_heightPixels = getResources().getDisplayMetrics().widthPixels * 9f / 16f;

//取消全屏

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

if (isLand) {

screen_heightPixels = getResources().getDisplayMetrics().heightPixels;

//设置全屏

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

}

rl_paramters.width = (int) screen_widthPixels;

rl_paramters.height = (int) screen_heightPixels;

//获取MediaPlayer的宽高

int videoWidth = mediaPlayer.getVideoWidth();

int videoHeight = mediaPlayer.getVideoHeight();

float video_por = videoWidth / videoHeight;

float screen_por = screen_widthPixels / screen_heightPixels;

//16:9 16:12

if (screen_por > video_por) {

sv_paramters.height = (int) screen_heightPixels;

sv_paramters.width = (int) (screen_heightPixels * screen_por);

} else {

//16:9 19:9

sv_paramters.width = (int) screen_widthPixels;

sv_paramters.height = (int) (screen_widthPixels / screen_por);

}

mRlVideo.setLayoutParams(rl_paramters);

mSvVideo.setLayoutParams(sv_paramters);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值