Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/316.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:如何在java中使小部件全屏显示_Java_Android_Android Relativelayout - Fatal编程技术网

Android:如何在java中使小部件全屏显示

Android:如何在java中使小部件全屏显示,java,android,android-relativelayout,Java,Android,Android Relativelayout,我想制作一个在JAVA代码中全屏显示的RelativeLayout 在这个相对图中,我想有两个ImaveView,一个在左上角,高50,重50,另一个在左上角,并且“匹配父对象” 现在我有: relativeLayout = new RelativeLayout(this); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_

我想制作一个在JAVA代码中全屏显示的RelativeLayout

在这个相对图中,我想有两个ImaveView,一个在左上角,高50,重50,另一个在左上角,并且“匹配父对象”

现在我有:

relativeLayout = new RelativeLayout(this);
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    relativeLayout.setLayoutParams(lp);

    im = new ImageView(this);
    im.setLayoutParams(new LayoutParams(50,50));

    im2 = new ImageView(this);
    im2.setScaleType(ImageView.ScaleType.FIT_XY);
    im2.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));

    relativeLayout.addView(im2);
    relativeLayout.addView(im);
但是第一个图像没有显示,第二个图像只显示了全部的重量

这是我想要的图像:
你能检查一下这个代码吗

 RelativeLayout relativeLayout = new RelativeLayout(this);
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        relativeLayout.setLayoutParams(lp);


        ImageView im = new ImageView(this);
        im.setLayoutParams(new RelativeLayout.LayoutParams(50, 50));
        im.setImageResource(R.color.accent);
        ImageView im2 = new ImageView(this);
        im2.setScaleType(ImageView.ScaleType.FIT_XY);
        im2.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
        im2.setImageResource(R.color.orderProcessing);
        relativeLayout.addView(im2);
        relativeLayout.addView(im);
        setContentView(relativeLayout);

如果您想让image1与image2重叠,那么应该使用Framelayout。@XML中的SagarPujari我有RelativeLayout,它工作得很好,如果我将image1放在image2之后,它工作得很好。我只是想知道我如何在Java中做同样的事情谢谢它工作得很好,我很累,没有看到我犯的所有错误^ ^