Textview code – Design and animation in Java programming

Simple text is good for easily read and simple view but it’s not good in every site. Sometimes we build different types application and we personalized various types of design and much more. in this post i write the code for your project about textview and textview design.

Create textview

final TextView mytext = new TextView(ProjectinActivity.this); mytext.setText(“Your Text”); mytext.setTextColor(0xFF000000); mytext.setLayoutParams(new LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.WRAP_CONTENT, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT)); mylinear.addView(mytext);

This code for create new textview.

Textview Set size

text_id.setTextSize((float)14);

Replace size value to 14 as you want.

STD out to textview

java.lang.System.setOut(new java.io.PrintStream(new java.io.OutputStream() {
java.io.ByteArrayOutputStream outputStream = new java.io.ByteArrayOutputStream();
@Override
public void write(int oneByte) throws java.io.IOException {
outputStream.write(oneByte);
text_id.setText(new String(outputStream.toByteArray()));
}
}));
//Testing the System.out stream
java.lang.System.out.println(“Test”);
java.lang.System.out.println(“Test 2”);

this code is used to std out means 1st textview is small and all second textview is big than previous textview

Sample

Textview blinking animation

Animation anim =new AlphaAnimation(0.0f,1.0f);
anim.setDuration(50);
anim.setStartOffset(20);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
text_id.startAnimation(anim);

Use this code for blinking the text. You can also change value of this code as you want.

Textview FadeIn animation

final AlphaAnimation fadeIn = new AlphaAnimation(1.0f,0.0f);
final AlphaAnimation fadeOut = new AlphaAnimation(0.0f,1.0f);

text.startAnimation(fadeIn);
text.startAnimation(fadeOut);
fadeIn.setDuration(1200);
fadeIn.setFillAfter(true);
fadeOut.setDuration(1200);
fadeOut.setFillAfter(true);
fadeOut.setStartOffset(10+fadeIn.getStartOffset());

Replace text to text_id.

You can also change duration of animation.

Textview FadeOut animation

final AlphaAnimation fadeIn = new AlphaAnimation(0.0f,1.0f);
final AlphaAnimation fadeOut = new AlphaAnimation(1.0f,0.0f);

text.startAnimation(fadeIn);
text.startAnimation(fadeOut);
fadeIn.setDuration(1200);
fadeIn.setFillAfter(true);
fadeOut.setDuration(1200);
fadeOut.setFillAfter(true);
fadeOut.setStartOffset(10+fadeIn.getStartOffset());

Replace text to text_id.

Here also change direction of animation.

Textview movie animation

TranslateAnimation translateAnimation = new TranslateAnimation (Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,.85f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0.65f);
translateAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
translateAnimation.setDuration(1200);
text.startAnimation(translateAnimation);

Replace text to text_id.

Textview Rotate anticlockwise animation

RotateAnimation rotateAnimation = new RotateAnimation(360, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setInterpolator(new AccelerateInterpolator());
rotateAnimation.setDuration(3000);
text.startAnimation(rotateAnimation);

Replace text to text_id.

You may change rotate value 1 to 360 and also can change duration of animation.

Textview rotate clockwise animation

RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotateAnimation.setInterpolator(new LinearInterpolator()); rotateAnimation.setDuration(3000); text.startAnimation(rotateAnimation);

Replace text with text_id.

You can change rotate value and also duration of animation.

Textview zoom in animation

ScaleAnimation scaleAnimation = new ScaleAnimation(1f,4f,1f,4f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setInterpolator(new LinearInterpolator());
scaleAnimation.setDuration(1800);
text.startAnimation(scaleAnimation);

Replace text to text_id.

You can change duration of animation.

Textview zoomOut animation

ScaleAnimation scaleAnimation = new ScaleAnimation(1f,0.5f,1f,.50f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
scaleAnimation.setDuration(1800);
text.startAnimation(scaleAnimation);

Replace text to text_id.

You can change duration of animation.

Textview Deboss effect

EmbossMaskFilter filter = new EmbossMaskFilter(
new float[]{ 0f, -1f, 0.5f }, // direction of the light source
0.8f, // ambient light between 0 to 1
13, // specular highlights
7.0f // blur before applying lighting
);
text.setLayerType(View.LAYER_TYPE_SOFTWARE,null);
text.getPaint().setMaskFilter(filter);

Replace text to text_id.

I hope this code helpful for you thanks for visit.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.