Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何以编程方式将视图放在约束布局中其他视图的背面_Android_Performance_Android Layout_Android Constraintlayout - Fatal编程技术网

Android 如何以编程方式将视图放在约束布局中其他视图的背面

Android 如何以编程方式将视图放在约束布局中其他视图的背面,android,performance,android-layout,android-constraintlayout,Android,Performance,Android Layout,Android Constraintlayout,我使用了约束布局,并在视图中添加了2个按钮 现在我想在其中添加一个背景图像,但我将以编程方式添加 这就是我添加图像所做的 ConstraintLayout constraintLayout; constraintLayout= (ConstraintLayout) findViewById(R.id.main_constraint_Layout); ImageView imageView = new ImageView(t

我使用了约束布局,并在视图中添加了2个按钮

现在我想在其中添加一个背景图像,但我将以编程方式添加

这就是我添加图像所做的

            ConstraintLayout constraintLayout;
            constraintLayout= (ConstraintLayout) findViewById(R.id.main_constraint_Layout);

            ImageView imageView = new ImageView(this);
            imageView.setImageDrawable(imageDrawable);
            imageView.setId(View.generateViewId());
            constraintLayout.addView(imageView);

            ConstraintSet set = new ConstraintSet();
            set.clone(constraintLayout);

            set.connect(imageView.getId(), ConstraintSet.TOP, button2.getId(), ConstraintSet.TOP);

上面的代码所做的是在
按钮2
上添加一个图像,我希望它在
按钮2
后面绘制图像,而不是在
按钮2
上。如果is是从xml来实现的,这会容易得多,但我无法理解如何通过编程实现这一点

你有没有想过将eg-ViewStub添加到包含背景的xml中?我不知道,只是用谷歌搜索了一下。当然,你也可以将eg-FrameLayout添加为与父级匹配的子级,然后只添加ImageViewinside@Kirmani88你能分享你的预期布局吗
constraintLayout.setBackgroundResource(R.drawable.background);