android - Align drawable image inside a text view to center -


I have a text view that has an image and some text.

programmatic as I left the drawable Image text view

  txtIDFav.setCompoundDrawablesWithIntrinsicBounds (R.drawable.fav_enabled, 0, 0, 0);  

I have combined the text view using the center

  txtIDFav.setGravity (Gravity.CENTER);  

Now the text is aligned to the center in the text view. But the image is on the left

For example: .. The [image] _____________________ mytext

used as _ to not place your permission

I center the text to align image For example:

For example: .. _____________________ [Image] mytext

Please advice

Thanks and appreciate. In

I think textView width because it is set to Mac_perent or filling. Try textview width not only wrap_content and centering the whole textView text to try

layout :?

  & lt; XML version = "1.0" encoding = "utf-8"? & Gt; & Lt; Fremleaut xmlns: android = "http://schemas.android.com/apk/res/android" Android: layout_width = "match_parent" Android: layout_height = "match_parent" & gt; & Lt; TextView android: id = "@ + id / textViewTest" Android: Layout_width = "Wrap_content" Android: Layout_height = "Wrap_content" Android: Layout_gravity = "Center_horizontal" android: text = "test" Android: textSize = "28sp" / & gt ; & Lt; / FrameLayout & gt;  

Activity:

  extends public square MainActivity AppCompatActivity {@Override protected void OnCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); SetContentView (R.layout.activity_main); TextView Text ViewTest = (TextView) findViewById (R.id.textViewTest); TextViewTest.setCompoundDrawables with differentbounds (R.mipmap.ic_launcher, 0, 0, 0); }}  


Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -