如何在画中画模式下创建自定义布局?
Posted
技术标签:
【中文标题】如何在画中画模式下创建自定义布局?【英文标题】:How to create custom layout in Picture in Picture mode? 【发布时间】:2019-09-21 15:17:33 【问题描述】:我需要在我的应用中实现画中画模式。
-
在我的应用时间时钟页面中,当我选择时间时,计时器在画中画模式视图中启动。下课要不要大屏?
在画中画视图中,如何创建自定义布局?
注意:我在这个类中使用片段(如何在片段类中以编程方式设置这一行android:supportsPictureInPicture="true"
)
我已附上示例图片供您参考。请参考。
【问题讨论】:
你找到什么了吗? 【参考方案1】:我正在使用 DraggblePanel 来实现相同类型的效果
private void initializeDraggablePanel(Fragment fragmentView, Fragment bottomFragment)
draggablePanel.removeAllViews();
draggablePanel.setFragmentManager(getSupportFragmentManager());
draggablePanel.setTopFragment((Fragment) fragmentView);
draggablePanel.setBottomFragment(bottomFragment);
draggablePanel.setVisibility(View.VISIBLE);
draggablePanel.setClickToMaximizeEnabled(true);
draggablePanel.setDraggableListener(new DraggableListener()
@Override
public void onClosedToLeft()
draggablePanel.removeAllViews();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
@Override
public void onMinimized()
isFullScFromMini = true;
pipHandler.removeCallbacks(runnapipa);
pipHandler.postDelayed(runnapipa, PIP_DELAY);
draggablePanel.disableBottomView(true);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
@Override
public void onClosedToRight()
draggablePanel.removeAllViews();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
@Override
public void onUnMaximized()
draggablePanel.disableBottomView(false);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
@Override
public void onMaximized()
isFullScFromMini = true;
pipHandler.removeCallbacks(runnapipa);
pipHandler.postDelayed(runnapipa, PIP_DELAY);
draggablePanel.disableBottomView(false);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
);
TypedValue typedValue = new TypedValue();
getResources().getValue(R.dimen.x_scale_factor, typedValue, true);
float xScaleFactor = typedValue.getFloat();
typedValue = new TypedValue();
getResources().getValue(R.dimen.y_scale_factor, typedValue, true);
float yScaleFactor = typedValue.getFloat();
draggablePanel.setXScaleFactor(xScaleFactor);
draggablePanel.setYScaleFactor(yScaleFactor);
draggablePanel.setTopViewHeight(
getResources().getDimensionPixelSize(R.dimen.top_fragment_height));
draggablePanel.setTopFragmentMarginRight(
getResources().getDimensionPixelSize(R.dimen.top_frag_right_margin));
draggablePanel.setTopFragmentMarginBottom(
getResources().getDimensionPixelSize(R.dimen.top_fragment_margin));
draggablePanel.initializeView();
draggablePanel.maximize();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
完整的示例检查Link
【讨论】:
以上是关于如何在画中画模式下创建自定义布局?的主要内容,如果未能解决你的问题,请参考以下文章