Tuesday, July 9, 2013

[android help] Image + Text to be centre alligned in button


Image + Text to be centre alligned in button


android - Image + Text to be centre alligned in button - Stack Overflow







Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















I have a Button with its width as match_parent. And I want a image/icon with a text in its center. I have triedandroid:drawableStart attribute but its of no help. I don't know what I am missing. Is there any one who is also facing the same problem.


Note:This link is not solving my problem. I am attaching my button portion of xml



android:background="@drawable/blue_button"
android:id="@+id/btn_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:drawableStart="@drawable/ic_list"
android:text="@string/btn_schedule"
android:textColor="@android:color/white" />


After adding these attribute my text is coming on center but image/icon is still on left side of button. Can any body help!!!





























You might want to check my answer to this question: Android Button with text and image


Its an ugly solution but it you want the image and text to be centered as a group in the button rather than text center and drawable padded from the side then its the only way I have found.























Use layout gravity attribute as follows



android:Layout_gravity="center"


if above not working the put this button in a linear layout and inside the linear layout put gravity attribute.


That will surely work. please share your knowledge if its not working.




















default






Read more

stackoverflow.comm



No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...