Android板实现双屏显示,DisplayManager和Display的使用

  • Post author:
  • Post category:其他


非常简单。

效果

1、创建分屏管理类

DisplayController
public class DisplayController {
    public static Display getTargetDisplay() {
        DisplayManager displayManager = (DisplayManager) App.getInstance().getSystemService(Context.DISPLAY_SERVICE);
        Display[] presentationDisplays = displayManager.getDisplays(null);


        LogPlus.e("###显示器数量->" + presentationDisplays.length);
        if (presentationDisplays.length == 0) {
            return null;
        }
        return presentationDisplays[presentationDisplays.length - 1];
    }

    public static void showDataView(DataViewPresentation dataViewPresentation) {
        dataViewPresentation.show();
    }

    public static void dissDataView(DataViewPresentation dataViewPresentation) {
        dataViewPresentation.dismiss();
    }
}

2、创建界面基类

/**
 * 数据展示 大屏
 */
public abstract class DataViewPresentation extends Presentation {
    protected View layoutView;

    public DataViewPresentation(Context outerContext, Display display) {
        super(outerContext, display);
    }

    public DataViewPresentation(Context outerContext, Display display, int theme) {
        super(outerContext, display, theme);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        layoutView = getLayoutView();
        setContentView(layoutView);
        init();
    }

    protected abstract View getLayoutView();

    protected void init() {

    }
}

实现demo:

https://download.csdn.net/download/meixi_android/13610774

bug在线交流: QQ1085220040



版权声明:本文为meixi_android原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。