Here is my simple background selector:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/filters_group_pressed" android:state_pressed="true"/>
    <item android:drawable="@drawable/filters_group_pressed" android:state_selected="true"/>
    <item android:drawable="@drawable/filters_group"/>

</selector>

In the layout editor layout look's like: enter image description here

After launching on nexus 7 (first generation) it look's like: enter image description here

It looks fine if I set as background my 9patch graphic (which selector contains) and not the selector. It looks like an android bug to me...

White bar should be stretched at whole width and the icon should be centered. Here is the layout:

<org.mycustomview.MyCustomLinearLayout
    android:id="@+id/group_button"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:background="@drawable/filter_group_button_selector"
    android:gravity="center"
    android:clickable="true"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/icon_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_table" />

    <TextView
        android:id="@+id/title_label"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Sala 1"
        android:lines="1"
        android:paddingLeft="2dp"
        android:paddingRight="2dp"
        android:background="@color/white"
        android:gravity="center"
        android:textColor="@color/white" />
</org.mycustomview.MyCustomLinearLayout>
有帮助吗?

解决方案

It must be a bug. It added right padding itself. I added android:paddingRight="0dp" to my MyCustomLinearLayout and it's work like expected.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top