I am comparatively new to Android.
Description –
I have a LinearLayout with TextView‘s in it.
I am adding the TextView dynamically.
When I touch the TextView, I want it to ScaleUp and when I touch the same TextView again I want it to ScaleDown.
My problems are –
- When a
TextViewisscaled upand any otherTextViewistouched. The olderTextViewshouldscale downand the newtouchedTextViewshouldscale up. - When I touch a
scaled upTextViewthen thisTextViewshould scale down.
This is what I have tried
I have 2 set xmls. 1 for scale up
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="3.0"
android:toYScale="3.0" >
</scale>
and the other for scale down
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:fromXScale="3.0"
android:fromYScale="3.0"
android:toXScale="1.0"
android:toYScale="1.0" >
</scale>
My Activity class –
myTextView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (myTextView.getAnimation() == null) {
Animation a = AnimationUtils.loadAnimation(
getBaseContext(), R.anim.scale_up);
a.setFillAfter(true);
v.startAnimation(a);
} else {
v.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v1,
MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
Animation a1 = AnimationUtils
.loadAnimation(
getBaseContext(),
R.anim.scale_down);
a1.setFillAfter(true);
v1.startAnimation(a1);
}
return true;
}
});
}
}
return false;
}
});
make an collection of textviews and store states in them.. on every touch you loop this collection and search for the right textview and do appropriate things with it. You can also search trough this collection and check which textviews are scaled up or down since you are managing the states yourself.