Question

in our app we have some toggle buttons with custom skin. The problem is visible on next picture. The toggle indicator isn't centered well. This problem appears only on devices whit higher resolution...for example on Nexus 7

enter image description here

Here is some code how we have defined skin

<!-- TOGGLE -->
<style name="Toggle">
    <item name="android:textSize">@dimen/toggle_text_size</item>
    <item name="android:paddingLeft">@dimen/button_padding_left</item>
    <item name="android:paddingRight">@dimen/button_padding_right</item>
    <item name="android:background">@drawable/toggle_bg_selector</item>
    <item name="android:textColor">@drawable/toggle_text_color_selector</item>
    <item name="android:minHeight">0dip</item>
    <item name="android:singleLine">true</item>
</style>

button_padding_left and button_padding_right is both 3dip

toggle_bg_selector:

<selector xmlns:android="http://schemas.android.com/apk/res/android">   
    <item 
        android:state_checked="true" 
        android:state_pressed="true" 
        android:drawable="@drawable/toggle_bg_on" />       
    <item 
        android:state_pressed="true" 
        android:drawable="@drawable/toggle_bg_on" />        
    <item 
        android:state_checked="true" 
        android:drawable="@drawable/toggle_bg_on" />        
    <item 
        android:drawable="@drawable/toggle_bg_off" />  
</selector>

And yes the drawable images are centered correctly.

Thank you for any responce.

Was it helpful?

Solution

Ok, problem solved. It was a bad 9 patch picture. The scale area was 1 or 2 pixels wider on left side than on the right side.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top