Now I wanted to use an effect, that the letter "i" of the word "Ecl pse" appears firstly bigger and gets smaller, after I clicked on the button. But with the following code the whole word "Eclipse" is bigger and gets smaller then
public class Pagetwo extends Activity implements OnClickListener {
public Button btn;
public TextView tw;
Animation a;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.pagetwo);
btn = (Button) findViewById(R.id.BtnKlick);
tw = (TextView) findViewById(R.id.tvhallo);
a= AnimationUtils.loadAnimation(this, R.anim.scale);
btn.setOnClickListener(this);
SpannableString text = new SpannableString("Ecl pse");
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String text = tw.getText().toString();
int n = 3;
String newText = text.substring(0, n) + "i" + text.substring(n + 1);
tw.setText(newText);
tw.startAnimation(a);
{}}}
You aren't defining your animation in the correct place nor are you applying it to the text view.
Try this:
public class Pagetwo extends Activity implements OnClickListener {
public Button btn1;
public TextView tw1;
Animation a;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1 = (Button) findViewById(R.id.BtnKlick);
tw1 = (TextView) findViewById(R.id.tvhallo);
a= AnimationUtils.loadAnimation(this, R.anim.scale);
btn1.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
tw1.setText("Hallo");
tw1.startAnimation(a);
}
}