2

Hi I have just started making android apps and I understand that buttons in androids have different states: pressed, normal, focused etc.

I have a totally different button for when it is pressed, but the pressed button is much bigger than the normal button.

I placed a selector xml file in the background of the xml file but it gives me an even smaller button when pressed.

Can anyone shed some light on this?

xml of page, with c being the button.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent"
             android:layout_height="fill_parent"

             android:layout_marginTop="0dp"
             tools:context="package.MainFragment"
             android:id="@+id/root_layout"
             android:background="@drawable/background">

    <ImageView
            android:layout_width="250dp"
            android:layout_height="50dp"
            android:scaleType="fitCenter"
            android:adjustViewBounds="true"
            android:id="@+id/a"
            android:src="@drawable/a"
            android:layout_gravity="center_horizontal|top"/>
    <ImageView
            android:layout_width="200dp"
            android:layout_height="180dp"
            android:scaleType="fitCenter"
            android:adjustViewBounds="true"
            android:id="@+id/b"
            android:src="@drawable/b"
            android:layout_gravity="center"/>
    <ImageButton
            android:layout_width="180dp"
            android:layout_height="20dp"
            android:scaleType="fitCenter"
            android:adjustViewBounds="true"
            android:id="@+id/c"
            android:background="@drawable/c"
            android:layout_gravity="center_horizontal|bottom"/>
</FrameLayout>

selector file of c:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/c_pressed"
              android:state_pressed="true"/>
        <item android:drawable="@drawable/c_normal"/>
</selector>
Hanzawa Naoki
  • 505
  • 1
  • 8
  • 19
  • Make sure the images you are using in selector xml are kept in same drawable folder ie either in drawable or drawable-hdpi or so on..... – A.R. Apr 21 '15 at 17:33

0 Answers0