Reputation: 2445
Is it possible to do some image affects on images to simulate pressed state? (to reduce the size of the APK)
Upvotes: 1
Views: 89
Reputation: 7820
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/button_pressed" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/button_focused" /> <!-- focused -->
<item android:drawable="@drawable/button_normal" /> <!-- default -->
</selector>
and then each button can be defined in XML as well:
button_normal:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#DD63594A"
android:endColor="#809C7D5A"
android:angle="90"/>
<stroke android:width="2dp" android:color="#FF524539" />
<!-- android:dashWidth="2dp" android:dashGap="1dp" /> -->
<padding android:left="4dp"
android:top="4dp"
android:right="4dp"
android:bottom="4dp"/>
<corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
</shape>
button_pressed:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#80A57D08"
android:endColor="#DDE75D31"
android:angle="90"/>
<stroke android:width="2dp" android:color="#FF524539" />
<!-- android:dashWidth="2dp" android:dashGap="1dp" /> -->
<padding android:left="4dp"
android:top="4dp"
android:right="4dp"
android:bottom="4dp"/>
<corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
</shape>
button_focused:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#80E75D31"
android:endColor="#DDE75D31"
android:angle="90"/>
<stroke android:width="2dp" android:color="#FF524539" />
<!-- android:dashWidth="2dp" android:dashGap="1dp" /> -->
<padding android:left="4dp"
android:top="4dp"
android:right="4dp"
android:bottom="4dp"/>
<corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
</shape>
As far as animation, it really depends on what you want to do and to what end:
You can make your own (frame-by-frame) for example: http://www.twintechs.com/2008/06/frame-by-frame-xml-animation-with-google-android/ & http://code.google.com/p/android-animation-example/
Or use AnimatedViews: http://mylifewithandroid.blogspot.com/2008/04/animated-views.html
Hope that helps. That will save space ;-)
FYI: If you are looking for compression look no further than http://trimage.org/
Upvotes: 1