You create layout parameters from the LinearLayout.LayoutParams class. However, the image is added to the FrameLayout . This is not true because you apply only the layout options of the parent to the view. So, in your case, it should be:
ImageView imageView = KaHOUtility.generateImageView(mContext, 15, 15, R.drawable.cancel_mark); FrameLayout.LayoutParams rPrams = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); rPrams.gravity = Gravity.RIGHT | Gravity.TOP ; imageView.setLayoutParams(rPrams); frameLayout.addView(imageView);
source share