gpt4 book ai didi

java - 无法在第二个屏幕上制作全屏 Android 演示文稿

转载 作者:行者123 更新时间:2023-12-01 12:07:15 24 4
gpt4 key购买 nike

我的问题是关于利用设备辅助屏幕的 Android 设施,即 android.app.Presentation

我正在使用这个包装器:https://github.com/commonsguy/cwac-presentation

不幸的是,我无法强制第二个屏幕布局处于全屏模式:尽管其宽度与屏幕完全匹配,但其高度始终限制在屏幕中心的条纹,大约是屏幕高度的 1/4

相应地,其所有内容都显示在这个狭窄的边界内,而屏幕的其余部分则保持黑色且无用

对于那些不了解此 API 的人,
android.app.Presentation 是一种特殊类型的 Dialog,显示在设备的辅助屏幕上,
我上面提到的包装器基于扩展了 DialogFragmentPresentationFragment。用户创建一个扩展 PresentationFragment 的类,并在其重写的 onCreateView() 中创建他希望在第二个屏幕上显示的布局。示例:

    public class CustomPresentationFragment extends PresentationFragment {

public static CustomPresentationFragment newInstance(Context ctxt,
Display display) {

CustomPresentationFragment frag=new CustomPresentationFragment();

frag.setDisplay(ctxt, display);

//we may prepare bundle to pass, if necessary
//Bundle b=new Bundle();
//b.putString("key1", value1);
//b.putString("key2", value2);
//frag.setArguments(b);

return(frag);
}



@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {

View myView = new View(getContext());

//here we create layout that we want to be displayed on second screen, and return it

return(myView);

}


}

这是PresentationFragment的实现。正如我们所看到的,它包含 Presentation 变量:

package com.commonsware.cwac.preso;

import android.app.Dialog;
import android.app.DialogFragment;
import android.app.Presentation;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;

public abstract class PresentationFragment extends DialogFragment
{
private Display display = null;
private Presentation preso = null;

public Dialog onCreateDialog(Bundle savedInstanceState)
{
if (this.preso == null) {
return super.onCreateDialog(savedInstanceState);

//instead of simply returning super value, I have tried the following here,
//with no success:
//
//Dialog dlg = super.onCreateDialog(savedInstanceState);
//dlg.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
//dlg.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//dlg.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
//return dlg;

}

return this.preso;
}

public void setDisplay(Context ctxt, Display display) {
if (display == null) {
this.preso = null;
}
else {
this.preso = new Presentation(ctxt, display, getTheme());

//since Presentation is Dialog, I have tried the same here as well,
//no success:

//this.preso.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
//this.preso.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//this.preso.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);


}

this.display = display;
}

public Display getDisplay() {
return this.display;
}

protected Context getContext() {
if (this.preso != null) {
return this.preso.getContext();
}

return getActivity();
}
}

编辑。这是我的一个PresentationFragments 中的onCreateView():

@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {

String uri = "somefilepath";
File imgFile = new File(uri);
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());

ImageView view = new ImageView(getContext());
view.setImageBitmap(myBitmap);
view.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

RelativeLayout pRelative = new RelativeLayout(getContext());
pRelative.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
pRelative.setGravity(Gravity.CENTER);

pRelative.addView(view);

return pRelative;

}

最佳答案

首先,您的 RelativeLayout 的父级可能不是另一个 RelativeLayout,因此您不应该尝试设置 RelativeLayoutLayoutParamsRelativeLayout.LayoutParams 的实例。

其次,将其重写为 XML 布局并对其进行扩充。那么你的 RelativeLayout 就有更好的机会工作,因为它会在膨胀时知道它的父级。 RelativeLayout 是一个挑剔的野兽。另一种选择是从 RelativeLayout 切换到其他可以居中的东西,例如 FrameLayout

关于java - 无法在第二个屏幕上制作全屏 Android 演示文稿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27500682/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com