【发布时间】:2015-02-09 00:30:42
【问题描述】:
我正在尝试将视图的状态从不可见更改为可见,并且我还希望有从左到右显示它的动画(不移动)。
我在jquery中做的例子:
$(".slide").animate({width:'toggle'},3000);
谢谢
【问题讨论】:
我正在尝试将视图的状态从不可见更改为可见,并且我还希望有从左到右显示它的动画(不移动)。
我在jquery中做的例子:
$(".slide").animate({width:'toggle'},3000);
谢谢
【问题讨论】:
您不一定需要更改文本的可见性,您可以用另一个覆盖视图,然后将重叠的动画从可见到消失:
活动:
public class MainActivity extends Activity {
private View coverView;
private TextView txtText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
coverView = findViewById(R.id.coverView);
txtText = (TextView) findViewById(R.id.txtText);
coverView.post(new Runnable() {
@Override
public void run() {
move();
}
});
}
private void move() {
//Load animation
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.text_translate);
//Know when it ends to change visibility
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
coverView.setVisibility(View.GONE);
}
});
coverView.startAnimation(animation);
}
}
布局xml(main_activity.xml):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/txtText"
android:layout_width="120dp"
android:layout_height="50dp"
android:text="testtestetstesttest" />
<View
android:id="@+id/coverView"
android:layout_width="120dp"
android:layout_height="50dp"
android:background="@android:color/white" />
</RelativeLayout>
动画 XML.(位于 res/anim) text_translate.xml:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3000"
android:fromXDelta="0"
android:toXDelta="240" >
</translate>
你将不得不玩弄其他的东西,比如背景。如果您想要的只是使用 TextView 并翻译它,请在“fromDeltaX”中使用负值,在“toDeltaX”中使用 0。但是,结果与您的链接不同。
【讨论】: