Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button with 9-Patch background not wrapping content

OK I have a Button which uses as its background a selector. I set the width and height to wrap_content. The content is some text I set. I'm expecting the button to be sized around the text like a native button but the button is huge , basically looks as big as its source image. The button image is a nine patch image and the button xml is inside a relative layout. What am I missing here?

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/holo_btn" />
        <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/holo_btn" />
        <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/holo_btn" />
        <item android:drawable="@drawable/holo_btn" />
</selector>



<Button android:id="@+id/btnTaskPriorityLow" 
            android:paddingLeft="@dimen/paddingSmallButton" android:paddingRight="@dimen/paddingSmallButton"
            android:text="@string/strTaskPriorityLow"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:layout_below="@id/textViewCalColor"
            android:layout_toRightOf="@+id/textViewPriority"
            android:layout_marginTop="@dimen/marginTopAppt"
            android:background="@drawable/button_holo_sel"/>
like image 995
Mike6679 Avatar asked Dec 16 '22 15:12

Mike6679


1 Answers

If I understand you have a huge 9-Patch as background.

AFAIK, 9-Patch can be extended but not reduced. So you probably have to edit your 9-Patch to make it as small as possible. Usually you can reduce the center-strechable area to one pixel.

like image 176
ben75 Avatar answered Dec 20 '22 19:12

ben75