android文字下的line指示器

本文介绍了一个使用Android实现的简单指示器动画功能,通过设置动画持续时间和位移,实现不同选项之间的平滑过渡效果。

android动画:

一个简单的指示器功能。






package com.example.textviewandline;


import android.os.Bundle;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.View;
import android.view.ViewPropertyAnimator;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener{
	public TextView tab_hot1;
	public TextView tab_hot2;
	public TextView tab_hot3;
	public TextView tab_hot4;
	public View hot_underline;
	public View hot_underline2;
	//public LinearLayout view_hottab;
	//boolean isShow = true;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		tab_hot1 = (TextView)findViewById(R.id.tab_hot1);
		tab_hot2 = (TextView)findViewById(R.id.tab_hot2);
		tab_hot3 = (TextView)findViewById(R.id.tab_hot3);
		tab_hot4 = (TextView)findViewById(R.id.tab_hot4);
		hot_underline = findViewById(R.id.view_hotunderline);
		//view_hottab = (LinearLayout)findViewById(R.id.view_tag_hotpage);
		hot_underline2 = findViewById(R.id.view_hotunderline2);
		tab_hot1.setOnClickListener(this);
		tab_hot2.setOnClickListener(this);
		tab_hot3.setOnClickListener(this);
		tab_hot4.setOnClickListener(this);
		
	}
	@SuppressLint("NewApi")
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) { 
		case R.id.tab_hot1:
			hot_underline.animate().setDuration(350).translationX(0)
					.scaleX(0.6f);
			break;
		case R.id.tab_hot2:
			hot_underline.animate().setDuration(350)
					.translationX(hot_underline.getWidth()).scaleX(0.6f)
					;
			break;
		case R.id.tab_hot3:
			hot_underline.animate().setDuration(350)
					.translationX(hot_underline.getWidth() * 2).scaleX(0.6f)
					;
			break;
		case R.id.tab_hot4:
			int off = hot_underline2.getWidth() - hot_underline.getWidth();
			hot_underline.animate().setDuration(350)
					.translationX(hot_underline.getWidth() * 3 + off / 2)
					.scaleX(1f);
		}
	}
	/*
	@SuppressLint("NewApi")
	public void showHotTab() {
		view_hottab.setVisibility(View.VISIBLE);
		ViewPropertyAnimator anim = view_hottab.animate();
		anim.setDuration(300);
		if (isShow) {
			isShow = false;
			anim.translationYBy(-view_hottab.getHeight());
		} else {
			isShow = true;
			anim.translationY(0);
		}
	}*/
}


<LinearLayout 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"
    android:orientation="vertical"
    android:id="@+id/view_tag_hotpage"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="60dp"
        android:orientation="horizontal" >
        
        
          <TextView
            android:id="@+id/tab_hot1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="第一个"
            android:clickable="true"
           />

        <TextView
            android:id="@+id/tab_hot2"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="第二个"
            android:clickable="true"
             />

        <TextView
            android:id="@+id/tab_hot3"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="第三个"
            android:clickable="true"
           />

        <TextView
            android:id="@+id/tab_hot4"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1.5"
            android:gravity="center"
            android:text="最后一个文字"
            android:clickable="true"
            />
    </LinearLayout>
    
     <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="3dp"
        android:orientation="horizontal" >

        <View
            android:id="@+id/view_hotunderline"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:scaleX="0.6"
            android:background="#000000" />

        <View
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1" />

        <View
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1" />

        <View
            android:id="@+id/view_hotunderline2"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1.5" />
    </LinearLayout>

</LinearLayout>





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值