android中动给组建添加动画载入效果

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.testandroid.MainActivity" >

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="fill_parent"
        android:layout_height="60dip"
        android:layout_marginTop="60dip"
        android:visibility="gone"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/tv1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="#936"
            android:gravity="center"
            android:text="功能1"
            android:textColor="#fff"
            android:textSize="20dip" />

        <TextView
            android:id="@+id/tv2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="#693"
            android:gravity="center"
            android:text="功能2"
            android:textColor="#fff"
            android:textSize="20dip" />
    </LinearLayout>

    <TextView
        android:id="@+id/tv_title"
        android:layout_width="fill_parent"
        android:layout_height="60dip"
        android:background="#369"
        android:gravity="center"
        android:text="点击标题"
        android:textColor="#fff"
        android:textSize="20dip" />

</RelativeLayout>


MainActivity.java

package com.example.testandroid;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

	TextView tv_title;
	LinearLayout layout;
	TextView tv1, tv2;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		layout = (LinearLayout) findViewById(R.id.linearLayout);
		tv_title = (TextView) findViewById(R.id.tv_title);
		tv1 = (TextView) findViewById(R.id.tv1);
		tv2 = (TextView) findViewById(R.id.tv2);
		tv_title.setOnClickListener(onClickListener);
		tv1.setOnClickListener(onClickListener);
		tv2.setOnClickListener(onClickListener);
	}

	OnClickListener onClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			if (v == tv1) {
				Toast.makeText(MainActivity.this, "功能1", 0).show();
				layout.setVisibility(View.GONE);
			} else if (v == tv2) {
				Toast.makeText(MainActivity.this, "功能2", 0).show();
				layout.setVisibility(View.GONE);
			} else if (v == tv_title) {
				showMenu();
			}
		}
	};

	private void showMenu() {
		TranslateAnimation translateAnimation = new TranslateAnimation(
				Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f,
				Animation.RELATIVE_TO_SELF, -1f, Animation.RELATIVE_TO_SELF, 0f);
		translateAnimation.setDuration(200);
		layout.setVisibility(View.VISIBLE);
		layout.startAnimation(translateAnimation);
	}

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值