Deceptive Mind Deceptive Mind - 2 months ago 13
Android Question

Set Icon's position over Imageviews(inside frameLayout)

I am new to android.I have a question that i am trying to put icons over the FrameLayout.
enter image description here

Now,all the four colored triangular Boxes are the ImageViews in the different four FrameLayouts and all the four Frame Layouts are inside a RelativeLayout.

Now I want to put the icons over the 4 FrameLayouts.I am making these layouts in jaa not in XML.
So,I am not able to put these icons over the particular ImageView(framelayout);
I am using this code to set the position of icons over the particular frame or imageview,

ImageView icon = new ImageView(getBaseContext());
icon.setImageResource(R.drawable.wordpress_icon);
LayoutParams paramsIcon = new LayoutParams(50, 50);
MarginLayoutParams IconPara = new MarginLayoutParams(50,50);
// IconPara.setMargins(500, 500, 0, 0);
//icon.setPadding(0, 0, width-60, height-60);
icon.layout(50, 50, 0, 0);
icon.requestLayout();
icon.setLayoutParams(paramsIcon);


But after all , I am not able to put these icons over the specific place on the screen.

Answer

Please try your code with bellow code.

                FrameLayout frameLayout = new FrameLayout(
                            layout_A.getContext());
                frameLayout.addView(imageAndTextLayout);
                FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
                            android.widget.FrameLayout.LayoutParams.MATCH_PARENT,
                            android.widget.FrameLayout.LayoutParams.MATCH_PARENT);
                layoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT;

                icon.setLayoutParams(layoutParams);
                frameLayout.addView(textView);
                linearLayout.addView(frameLayout);
Comments