I have a textview which holds an image and some text.
programmatically i have added the drawable image to the left side of text view
txtIDFav.setCompound
I assume it is happened because the width of textView is set to match_parent
or fill_parent
. Try setting textView width to wrap_content
and center the whole textView not only text.
Layout:
Activity:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textViewTest=(TextView)findViewById(R.id.textViewTest);
textViewTest.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.ic_launcher, 0, 0, 0);
}
}
Result