View view1=new View(MainActivity.this); int x=getResources().getDisplayMetrics().widthPixels; int y=getResources().getDisplayMetrics().heightPixels; view1.setX(100); view1.setY(100); ConstraintLayout layout=(ConstraintLayout)findViewById(R.id.main); view1.setBackgroundColor(Color.RED); ConstraintLayout.LayoutParams layoutParams=new ConstraintLayout.LayoutParams(400,500); view1.setLayoutParams(layoutParams); // layout.addView(view1,layoutParams); if (Build.VERSION.SDK_INT>=21) { view1.setTranslationZ(100.0f); } else{ view1.bringToFront(); layout.requestLayout(); view1.invalidate(); }
添加 自定义的view,并显示在最前端
最新推荐文章于 2024-09-09 11:56:24 发布