Skip to content

Commit b6a9aca

Browse files
committed
Add animated example.
1 parent 7dad38d commit b6a9aca

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

res/layout/main.xml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,34 @@
99
<ImageView
1010
android:id="@+id/image1"
1111
android:layout_width="match_parent"
12-
android:layout_height="150dp"
12+
android:layout_height="100dp"
1313
android:scaleType="center"/>
1414
<ImageView
1515
android:id="@+id/image2"
1616
android:layout_width="match_parent"
17-
android:layout_height="150dp"
17+
android:layout_height="100dp"
1818
android:scaleType="centerCrop"/>
1919
</TableRow>
2020

2121
<TableRow>
2222
<ImageView
2323
android:id="@+id/image3"
2424
android:layout_width="match_parent"
25-
android:layout_height="150dp"
25+
android:layout_height="100dp"
2626
android:scaleType="center" />
2727
<ImageView
2828
android:id="@+id/image4"
2929
android:layout_width="match_parent"
30-
android:layout_height="150dp"
30+
android:layout_height="100dp"
3131
android:scaleType="fitCenter" />
3232
</TableRow>
3333

34+
<ImageView
35+
android:id="@+id/image5"
36+
android:layout_width="match_parent"
37+
android:layout_height="100dp"
38+
android:scaleType="fitCenter" />
39+
3440
<EditText
3541
android:id="@+id/edittext1"
3642
android:layout_width="match_parent"

src/com/example/textdrawable/MyActivity.java

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,27 @@
2626
import android.app.Activity;
2727
import android.graphics.Color;
2828
import android.graphics.Path;
29+
import android.graphics.drawable.ClipDrawable;
2930
import android.os.Bundle;
31+
import android.os.Handler;
3032
import android.text.Layout;
3133
import android.util.TypedValue;
34+
import android.view.Gravity;
3235
import android.widget.Button;
3336
import android.widget.EditText;
3437
import android.widget.ImageView;
3538
import com.example.textdrawable.drawable.TextDrawable;
3639

37-
public class MyActivity extends Activity {
40+
public class MyActivity extends Activity implements Runnable {
3841
//Row One
3942
ImageView mImageOne, mImageTwo;
4043
//Row Two
4144
ImageView mImageThree, mImageFour;
4245
//Row Three
43-
EditText mEditText;
46+
ImageView mImageFive;
4447
//Row Four
48+
EditText mEditText;
49+
//Row Five
4550
Button mButton;
4651

4752
@Override
@@ -53,12 +58,37 @@ public void onCreate(Bundle savedInstanceState) {
5358
mImageTwo = (ImageView) findViewById(R.id.image2);
5459
mImageThree = (ImageView) findViewById(R.id.image3);
5560
mImageFour = (ImageView) findViewById(R.id.image4);
61+
mImageFive = (ImageView) findViewById(R.id.image5);
5662
mEditText = (EditText) findViewById(R.id.edittext1);
5763
mButton = (Button) findViewById(R.id.button1);
5864

5965
loadDrawables();
6066
}
6167

68+
@Override
69+
protected void onResume() {
70+
super.onResume();
71+
//Start the animation
72+
mAnimator.post(this);
73+
}
74+
75+
@Override
76+
protected void onPause() {
77+
super.onPause();
78+
//Stop the animation
79+
mAnimator.removeCallbacksAndMessages(null);
80+
}
81+
82+
private Handler mAnimator = new Handler();
83+
private int mLevel = 0;
84+
@Override
85+
public void run() {
86+
mLevel = (mLevel += 25) % 10000;
87+
mImageFive.setImageLevel(mLevel);
88+
89+
mAnimator.postDelayed(this, 10);
90+
}
91+
6292
private void loadDrawables() {
6393
/*
6494
* Create a simple TextDrawable with all default settings.
@@ -105,6 +135,16 @@ private void loadDrawables() {
105135
mImageThree.setImageDrawable(d);
106136
mImageFour.setImageDrawable(d);
107137

138+
/*
139+
* Wrap a simple TextDrawable in a ClipDrawable to animate. One convenient
140+
* advantage of ImageView is we can call setLevel() on the view itself to affect
141+
* the Drawable content.
142+
*/
143+
d = new TextDrawable(this);
144+
d.setText("SHOW ME TEXT");
145+
ClipDrawable clip = new ClipDrawable(d, Gravity.LEFT, ClipDrawable.HORIZONTAL);
146+
mImageFive.setImageDrawable(clip);
147+
108148
/*
109149
* Construct a simple TextDrawable to act as a static prefix
110150
* inside of an EditText element

0 commit comments

Comments
 (0)