當前位置:編程學習大全網 - 源碼下載 - 如何讓壹個View從屏幕左邊慢慢移入

如何讓壹個View從屏幕左邊慢慢移入

main.xml文件:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

<TextView

android:id="@+id/tv"

android:visibility="invisible"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_weight="1"

android:text="@string/hello"

android:textColor="#FF0000"

android:background="@android:color/darker_gray"

android:gravity="center" />

<Button

android:id="@+id/btn"

android:text="start animation"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal" />

</LinearLayout>

package com.txlong;

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.Button;

import android.widget.TextView;

public class AndroidAnimationActivity extends Activity {

private Animation myAnimation_Translate;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

final TextView tv = (TextView) findViewById(R.id.tv);

Button btn = (Button) findViewById(R.id.btn);

btn.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

tv.setVisibility(View.VISIBLE);

myAnimation_Translate = new TranslateAnimation(

Animation.RELATIVE_TO_PARENT, -1,

Animation.RELATIVE_TO_PARENT, 0,

Animation.RELATIVE_TO_PARENT, 0,

Animation.RELATIVE_TO_PARENT, 0);

myAnimation_Translate.setDuration(1000);

myAnimation_Translate.setInterpolator(AnimationUtils

.loadInterpolator(AndroidAnimationActivity.this,

android.R.anim.accelerate_decelerate_interpolator));

tv.startAnimation(myAnimation_Translate);

}

});

}

}

  • 上一篇:Google、3M加入推動通用手寫筆技術規範 讓更多裝置能以手寫便利操作
  • 下一篇:批量源修改
  • copyright 2024編程學習大全網