Reputation: 7134
I am creating a custom button. I want to set the position of text on button.
But i am unable to set the exact position of the text on this background button image. Please share your suggestion to solve this issue.
Upvotes: 6
Views: 22556
Reputation: 399
You can use the layout as a button style="@android:style/Widget.Button"
, and configure it as you want.
Paste this in your xml file:
<LinearLayout
android:id="@+id/button"
style="@android:style/Widget.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:text="TextView" />
</LinearLayout>
Upvotes: 0
Reputation: 93
You can set these properties in XML file, `
<Button
android:id="@+id/button1"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:drawablePadding="5dp"
android:drawableLeft="@android:drawable/ic_lock_lock"
android:text="All"
android:gravity="center"/>
`
Upvotes: 3
Reputation: 545
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@android:drawable/arrow_down_float"
android:background="@drawable/btn_all_bg"
android:text="All">
Button>
You can use the drawableLeft/right/top/bottom to add icon on a button and text would automatically adjust.
Upvotes: 1
Reputation:
Few ways :
android:drawableStart
LinearLayout
that hold a text and an image with a
background of your button,
set both of them weight of 1 and put them inside another LinearLayout
and make them onClick
can't assure 3 will work without a tweak or two but it worth tryingUpvotes: 0
Reputation: 161
You can try using 9-patch image as a background. More information on this here: http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
Upvotes: 3