Set view images on the right side of the text field programmatically

I have to set the image to the Right Top textview programmatically. But its installation on the left side of the textview . Can someone tell me how to deal with this? My code is below:

  FrameLayout frameLayout = KaHOUtility.generateFrameLayout(mContext); frameLayout.setPadding(5, 5, 5, 5); LinearLayout linearLayout = KaHOUtility.generateLinearLayout(mContext); KaHOTextView textView = KaHOUtility.generatePanelHeadingTextViews(mContext); textView.setText(name); linearLayout.addView(textView); frameLayout.addView(linearLayout); ImageView imageView = KaHOUtility.generateImageView(mContext, 15, 15, R.drawable.cancel_mark); LinearLayout.LayoutParams rPrams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); rPrams.gravity = Gravity.RIGHT|Gravity.TOP ; imageView.setLayoutParams(rPrams); frameLayout.addView(imageView); 
+5
source share
1 answer

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); 
+3
source

All Articles