在上一个版本基础上添加两个Activity: EffectsActivity&TabLayoutActivity
EffectsActivity测试了一种效果;
TabLayoutActivity中使用的控件:
android.support.design.widget.TabLayout
android.support.v4.widget.NestedScrollView
android.support.design.widget.TextInputLayout
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.Button;
import android.widget.LinearLayout;
public class EffectsActivity extends AppCompatActivity implements View.OnClickListener{
private Context context;
private LinearLayout main_view;
private LinearLayout pop_view;
private int main_view_height;
private int pop_view_height;
private Button btn_show;
private Button btn_hide;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
context=this;
main_view = (LinearLayout)findViewById(R.id.main_view);
pop_view = (LinearLayout)findViewById(R.id.pop_view);
btn_show = (Button)findViewById(R.id.btn_show);
btn_hide = (Button)findViewById(R.id.btn_hide);
btn_show.setOnClickListener(this);
btn_hide.setOnClickListener(this);
main_view.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
main_view_height = main_view.getHeight();
main_view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});
pop_view.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
pop_view_height = pop_view.getHeight();
pop_view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btn_show:
show();
break;
case R.id.btn_hide:
hide();
break;
default:
break;
}
}
private void show(){
ObjectAnimator fViewScaleXAnim=ObjectAnimator.ofFloat(main_view,"scaleX",1.0f,0.8f);
fViewScaleXAnim.setDuration(350);
ObjectAnimator fViewScaleYAnim=ObjectAnimator.ofFloat(main_view,"scaleY",1.0f,0.8f);
fViewScaleYAnim.setDuration(350);
ObjectAnimator fViewAlphaAnim=ObjectAnimator.ofFloat(main_view,"alpha",1.0f,0.5f);
fViewAlphaAnim.setDuration(350);
ObjectAnimator fViewRotationXAnim = ObjectAnimator.ofFloat(main_view, "rotationX", 0f, 10f);
fViewRotationXAnim.setDuration(200);
ObjectAnimator fViewResumeAnim = ObjectAnimator.ofFloat(main_view, "rotationX", 10f, 0f);
fViewResumeAnim.setDuration(150);
fViewResumeAnim.setStartDelay(200);
ObjectAnimator fViewTransYAnim=ObjectAnimator.ofFloat(main_view,"translationY",0,-0.1f* main_view_height);
fViewTransYAnim.setDuration(350);
ObjectAnimator sViewTransYAnim=ObjectAnimator.ofFloat(pop_view,"translationY",pop_view_height,0);
sViewTransYAnim.setDuration(350);
sViewTransYAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
super.onAnimationStart(animation);
pop_view.setVisibility(View.VISIBLE);
btn_show.setEnabled(!pop_view.isShown());
}
});
AnimatorSet showAnim=new AnimatorSet();
showAnim.playTogether(fViewScaleXAnim,fViewRotationXAnim,fViewResumeAnim,fViewTransYAnim,fViewAlphaAnim,fViewScaleYAnim,sViewTransYAnim);
showAnim.start();
}
private void hide(){
ObjectAnimator fViewScaleXAnim=ObjectAnimator.ofFloat(main_view,"scaleX",0.8f,1.0f);
fViewScaleXAnim.setDuration(350);
ObjectAnimator fViewScaleYAnim=ObjectAnimator.ofFloat(main_view,"scaleY",0.8f,1.0f);
fViewScaleYAnim.setDuration(350);
ObjectAnimator fViewAlphaAnim=ObjectAnimator.ofFloat(main_view,"alpha",0.5f,1.0f);
fViewAlphaAnim.setDuration(350);
ObjectAnimator fViewRotationXAnim = ObjectAnimator.ofFloat(main_view, "rotationX", 0f, 10f);
fViewRotationXAnim.setDuration(200);
ObjectAnimator fViewResumeAnim = ObjectAnimator.ofFloat(main_view, "rotationX", 10f, 0f);
fViewResumeAnim.setDuration(150);
fViewResumeAnim.setStartDelay(200);
ObjectAnimator fViewTransYAnim=ObjectAnimator.ofFloat(main_view,"translationY",-0.1f* main_view_height,0);
fViewTransYAnim.setDuration(350);
ObjectAnimator sViewTransYAnim=ObjectAnimator.ofFloat(pop_view,"translationY",0,pop_view_height);
sViewTransYAnim.setDuration(350);
sViewTransYAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
pop_view.setVisibility(View.INVISIBLE);
btn_show.setEnabled(!pop_view.isShown());
}
});
AnimatorSet showAnim=new AnimatorSet();
showAnim.playTogether(fViewScaleXAnim,fViewRotationXAnim,fViewResumeAnim,fViewTransYAnim,fViewAlphaAnim,fViewScaleYAnim,sViewTransYAnim);
showAnim.start();
}
public boolean isShown(){
return pop_view.isShown();
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
if(isShown()){
hide();
}else{
super.onBackPressed();
}
}
}
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.Button;
import android.widget.LinearLayout;
public class EffectsActivity extends AppCompatActivity implements View.OnClickListener{
private Context context;
private LinearLayout main_view;
private LinearLayout pop_view;
private int main_view_height;
private int pop_view_height;
private Button btn_show;
private Button btn_hide;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_effects);
context=this;
main_view = (LinearLayout)findViewById(R.id.main_view);
pop_view = (LinearLayout)findViewById(R.id.pop_view);
btn_show = (Button)findViewById(R.id.btn_show);
btn_hide = (Button)findViewById(R.id.btn_hide);
btn_show.setOnClickListener(this);
btn_hide.setOnClickListener(this);
main_view.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
main_view_height = main_view.getHeight();
main_view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});
pop_view.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
pop_view_height = pop_view.getHeight();
pop_view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btn_show:
show();
break;
case R.id.btn_hide:
hide();
break;
default:
break;
}
}
private void show(){
ObjectAnimator fViewScaleXAnim=ObjectAnimator.ofFloat(main_view,"scaleX",1.0f,0.8f);
fViewScaleXAnim.setDuration(350);
ObjectAnimator fViewScaleYAnim=ObjectAnimator.ofFloat(main_view,"scaleY",1.0f,0.8f);
fViewScaleYAnim.setDuration(350);
ObjectAnimator fViewAlphaAnim=ObjectAnimator.ofFloat(main_view,"alpha",1.0f,0.5f);
fViewAlphaAnim.setDuration(350);
ObjectAnimator fViewRotationXAnim = ObjectAnimator.ofFloat(main_view, "rotationX", 0f, 10f);
fViewRotationXAnim.setDuration(200);
ObjectAnimator fViewResumeAnim = ObjectAnimator.ofFloat(main_view, "rotationX", 10f, 0f);
fViewResumeAnim.setDuration(150);
fViewResumeAnim.setStartDelay(200);
ObjectAnimator fViewTransYAnim=ObjectAnimator.ofFloat(main_view,"translationY",0,-0.1f* main_view_height);
fViewTransYAnim.setDuration(350);
ObjectAnimator sViewTransYAnim=ObjectAnimator.ofFloat(pop_view,"translationY",pop_view_height,0);
sViewTransYAnim.setDuration(350);
sViewTransYAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
super.onAnimationStart(animation);
pop_view.setVisibility(View.VISIBLE);
btn_show.setEnabled(!pop_view.isShown());
}
});
AnimatorSet showAnim=new AnimatorSet();
showAnim.playTogether(fViewScaleXAnim,fViewRotationXAnim,fViewResumeAnim,fViewTransYAnim,fViewAlphaAnim,fViewScaleYAnim,sViewTransYAnim);
showAnim.start();
}
private void hide(){
ObjectAnimator fViewScaleXAnim=ObjectAnimator.ofFloat(main_view,"scaleX",0.8f,1.0f);
fViewScaleXAnim.setDuration(350);
ObjectAnimator fViewScaleYAnim=ObjectAnimator.ofFloat(main_view,"scaleY",0.8f,1.0f);
fViewScaleYAnim.setDuration(350);
ObjectAnimator fViewAlphaAnim=ObjectAnimator.ofFloat(main_view,"alpha",0.5f,1.0f);
fViewAlphaAnim.setDuration(350);
ObjectAnimator fViewRotationXAnim = ObjectAnimator.ofFloat(main_view, "rotationX", 0f, 10f);
fViewRotationXAnim.setDuration(200);
ObjectAnimator fViewResumeAnim = ObjectAnimator.ofFloat(main_view, "rotationX", 10f, 0f);
fViewResumeAnim.setDuration(150);
fViewResumeAnim.setStartDelay(200);
ObjectAnimator fViewTransYAnim=ObjectAnimator.ofFloat(main_view,"translationY",-0.1f* main_view_height,0);
fViewTransYAnim.setDuration(350);
ObjectAnimator sViewTransYAnim=ObjectAnimator.ofFloat(pop_view,"translationY",0,pop_view_height);
sViewTransYAnim.setDuration(350);
sViewTransYAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
pop_view.setVisibility(View.INVISIBLE);
btn_show.setEnabled(!pop_view.isShown());
}
});
AnimatorSet showAnim=new AnimatorSet();
showAnim.playTogether(fViewScaleXAnim,fViewRotationXAnim,fViewResumeAnim,fViewTransYAnim,fViewAlphaAnim,fViewScaleYAnim,sViewTransYAnim);
showAnim.start();
}
public boolean isShown(){
return pop_view.isShown();
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
if(isShown()){
hide();
}else{
super.onBackPressed();
}
}
}
import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
public class TabLayoutActivity extends AppCompatActivity implements View.OnClickListener {
private Context context;
private TabLayout tabLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tablayout);
context = this;
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//使用了ActionBarDrawerToggle之后,下面的设置可以不用
// App Logo
// toolbar.setLogo(R.drawable.ic_launcher);
// Title
toolbar.setTitle("TabLayout");
// Sub Title
toolbar.setSubtitle("only a test");
//Navigation Icon
// toolbar.setNavigationIcon(R.drawable.ic_launcher);//不设置,默认是返回箭头
setSupportActionBar(toolbar);
//需要将setSupportActionBar(toolbar)放在setNavigationOnClickListener()之前设置才会响应click event
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
tabLayout = (TabLayout) findViewById(R.id.tabLayout);
tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 3"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 4"));
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
Test.rar (4.4 MB)
- 描述: android5.1.1编译,需要v7-appcompat,design等扩展包
- 下载次数: 0
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net