我遇到了一些问题。当我们将 setMeasuredDimension 设置为 (1,1) 时,它会变成黑屏。(我正在寻找后面的视图。但是当我们将(1,1)屏幕变为黑色时)如果我将setMeasuredDimension设置为(2,2),它的操作没有问题。你能说出原因吗?
我跟踪调用堆栈,我注意到当应用程序运行以显示 customView2 时,RenderNode.java 上的 nSetHasOverlappingRendering 函数被调用为 true,并且我们的电视设置为黑屏。
这是在 androidTV 上测试的,下面是我们的构建信息。compileSdkVersion:28 minSdkVersion:28 targetSdkVersion:28
谢谢大家。
-- MainActivity --(这是为了测试)
public class MainActivity extends Activity {
testCustomView2 testCustomView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
testCustomView = new testCustomView2(getApplicationContext());
WindowManager mWindowManager = (WindowManager)
getApplication().getSystemService(Context.WINDOW_SERVICE);
if (mWindowManager != null) {
WindowManager.LayoutParams wmparams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.OPAQUE);
wmparams.gravity = Gravity.TOP | Gravity.START;
mWindowManager.addView(testCustomView, wmparams);
}
}
}
--testCustomView2(这是为了测试)--
public class testCustomView2 extends View{
Context mContext;
public testCustomView2(Context context){
super(context);
mContext = context;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
this.setMeasuredDimension(1, 1);
}
}
-- activity_main.xml (res/layout)--
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_frame"
android:background="@android:color/transparent"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>