Android 多屏顯示

Android在SDK 17時,提供了多屏異步顯示。本篇將敘述如何在兩個屏幕中透過HDMI來達成異步顯示的方式。

Step 1: 檢視屏幕數量

1
2
3
4
5
6
DisplayManager  mDisplayManager = context.getSystemService(Context.DISPLAY_SERVICE);

Display[] displays = mDisplayManager.getDisplays();
Log.i(TAG, "Display Counts: " + displays.length);
//display[0] : 主要屏幕
//display[1] : 副屏幕

Step 2: 創建Presentation類別

首先我們要先創建class並繼承Presentation。
(Presentation類繼承Dialog類別)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class SubDislay extends Presentation {
public SubDislay(Context outerContext, Display display) {
super(outerContext, display);
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.sub_view);

//ImageView 的內容必須在此設置, 否則不會呈現
Resources r = getContext().getResources();
ImageView image = findViewById(R.id.imageView3);
image.setImageDrawable(r.getDrawable(R.drawable.pic2));
}
}

Step 3: 呈現畫面於副屏幕

在MainActivity.java中宣告SubDislay,並將畫面給予副屏幕呈現。

1
2
3
4
SubDislay  mPresentation =new SubDislay (this,displays[1]);
if(null != mPresentation) {
mPresentation.show();
}
作者

Nick Lin

發表於

2019-04-29

更新於

2023-01-18

許可協議


評論