TextView中各种Interpolator的使用

[size=large]Java代码
package net.blogjava.mobile.interpolators;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

public class Main extends Activity implements
AdapterView.OnItemSelectedListener {
private static final String[] INTERPOLATORS = { "Accelerate", "Decelerate",
"Accelerate/Decelerate", "Anticipate", "Overshoot",
"Anticipate/Overshoot", "Bounce" };

@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Spinner s = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, INTERPOLATORS);
adapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s.setAdapter(adapter);
s.setOnItemSelectedListener(this);
}

public void onItemSelected(AdapterView parent, View v, int position, long id) {
final View target = findViewById(R.id.target);
final View targetParent = (View) target.getParent();
Animation animation = new TranslateAnimation(0.0f, targetParent
.getWidth()
- target.getWidth()
- targetParent.getPaddingLeft()
- targetParent.getPaddingRight(), 0.0f, 0.0f);
animation.setDuration(1000);
animation.setStartOffset(300);
animation.setRepeatMode(Animation.RESTART);
animation.setRepeatCount(Animation.INFINITE);

switch (position) {
case 0:
animation.setInterpolator(AnimationUtils.loadInterpolator(this,
android.R.anim.accelerate_interpolator));
break;
case 1:
animation.setInterpolator(AnimationUtils.loadInterpolator(this,
android.R.anim.decelerate_interpolator));
break;
case 2:
animation.setInterpolator(AnimationUtils.loadInterpolator(this,
android.R.anim.accelerate_decelerate_interpolator));
break;
case 3:
animation.setInterpolator(AnimationUtils.loadInterpolator(this,
android.R.anim.anticipate_interpolator));
break;
case 4:
animation.setInterpolator(AnimationUtils.loadInterpolator(this,
android.R.anim.overshoot_interpolator));
break;
case 5:
animation.setInterpolator(AnimationUtils.loadInterpolator(this,
android.R.anim.anticipate_overshoot_interpolator));
break;
case 6:
animation.setInterpolator(AnimationUtils.loadInterpolator(this,
android.R.anim.bounce_interpolator));
break;
}

target.startAnimation(animation);
}

public void onNothingSelected(AdapterView parent) {
}
} [/size]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Android,你可以使用TextView来读取并显示文件内容。下面是一个简单的示例代码,演示如何从文件读取文本并将其显示在TextView: ```java import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class MainActivity extends AppCompatActivity { private TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView = findViewById(R.id.textView); // 读取文件 String fileContent = readFileContent("file.txt"); // 将文件内容显示在TextView textView.setText(fileContent); } private String readFileContent(String fileName) { File file = new File(getFilesDir(), fileName); StringBuilder content = new StringBuilder(); try { FileReader fileReader = new FileReader(file); BufferedReader bufferedReader = new BufferedReader(fileReader); String line; while ((line = bufferedReader.readLine()) != null) { content.append(line).append("\n"); } bufferedReader.close(); } catch (IOException e) { e.printStackTrace(); } return content.toString(); } } ``` 上述代码假设你有一个名为`file.txt`的文本文件存储在应用的内部存储目录(`getFilesDir()`)。你可以根据自己的需求修改文件名和文件路径。在此例,我们将文件内容读取到一个字符串,并将其设置为TextView的文本。 记得在你的布局文件(`activity_main.xml`)添加一个TextView控件: ```xml <TextView android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" android:textSize="16sp" /> ``` 这样,你就可以使用TextView来读取并显示文件内容了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值