android:resizeableActivity="true" android:supportsPictureInPicture="true" android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
PictureInPictureParams params = new PictureInPictureParams.Builder() .setAspectRatio(new Rational(10, 16)) .build();
@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig);
FrameLayout container = findViewById(R.id.local_video_view_container);
SurfaceView surfaceView = (SurfaceView) container.getChildAt(0);
surfaceView.setZOrderMediaOverlay(!isInPictureInPictureMode);
surfaceView.setVisibility(isInPictureInPictureMode ? View.GONE : View.VISIBLE);
container.setVisibility(isInPictureInPictureMode ? View.GONE : View.VISIBLE);
}
package com.example.myapplication;
import android.annotation.TargetApi;
import android.app.PictureInPictureParams;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.util.Rational;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;
/**
* 画中画
*/
public class TestPIPActivity extends AppCompatActivity {
private static final String TAG = "TestPIPActivity";
private PictureInPictureParams.Builder mPictureInPictureParamsBuilder;
@TargetApi(Build.VERSION_CODES.O)
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FrameLayout content = new FrameLayout(this);
setContentView(content,new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
if(Build.VERSION.SDK_INT == Build.VERSION_CODES.O){
mPictureInPictureParamsBuilder = new PictureInPictureParams.Builder();
final TextView textView = new TextView(this);
textView.setText("test PIP");
textView.setTextSize(20);
FrameLayout.LayoutParams fl = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
fl.gravity = Gravity.CENTER ;
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {//主要操作
Rational aspectRatio = new Rational(10,10);
mPictureInPictureParamsBuilder.setAspectRatio(aspectRatio).build();
enterPictureInPictureMode(mPictureInPictureParamsBuilder.build());
}
});
content.addView(textView,fl);
}else{
TextView descTv = new TextView(this);
descTv.setText("当前版本不支持...");
descTv.setTextSize(20);
FrameLayout.LayoutParams Tvfl = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
Tvfl.gravity = Gravity.CENTER ;
content.addView(descTv,Tvfl);
}
}
@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig);
Log.d(TAG,String.valueOf(isInPictureInPictureMode));
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有