編輯:關於Android編程
補間動畫amin——amin1 幀動畫drawable——amin2
if(id == R.id.action_settings) { //補間動畫 實例 Animation animation= AnimationUtils.loadAnimation(getBaseContext(),R.anim.anim1); an1.startAnimation(animation); }else if(id == R.id.action_settings1) { //幀動畫 an2.setBackgroundResource(R.drawable.anim2); animation=(AnimationDrawable)an2.getBackground(); animation.start(); }else if(id == R.id.action_settings2) { //屬性動畫 ObjectAnimator oja=ObjectAnimator.ofFloat(an3,"rotation",0,360); oja.setDuration(3000); oja.setRepeatCount(1); //設置插補器 oja.setInterpolator(newAccelerateDecelerateInterpolator()); oja.start(); }else if(id == R.id.action_settings3) { ObjectAnimator oja=ObjectAnimator.ofFloat(an4,"alpha",1,0); oja.setDuration(4000); oja.setRepeatCount(1); oja.setRepeatMode(ObjectAnimator.REVERSE); oja.setInterpolator(newLinearInterpolator()); oja.start(); }
漸進出現
點擊 交回 正常
點擊圖片動畫效果
1.動畫效果
package com.example.jreduch728; import android.animation.ObjectAnimator; import android.content.Intent; import android.graphics.drawable.AnimationDrawable; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.view.menu.MenuBuilder; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.view.animation.BounceInterpolator; import android.view.animation.LinearInterpolator; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; import java.lang.reflect.Method; public class Tool_barActivity extends AppCompatActivity { private TextView an1; private ImageView an2; private AnimationDrawable animation; private TextView an3; private TextView an4; private Button bt2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tool_bar); an1=(TextView)findViewById(R.id.an1) ; an2=(ImageView)findViewById(R.id.an2) ; an3=(TextView)findViewById(R.id.an3) ; an4=(TextView)findViewById(R.id.an4) ; bt2=(Button)findViewById(R.id.button2); bt2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(Tool_barActivity.this,MainActivity.class); startActivity(intent); //系統自帶動畫樣式左邊進右邊出 //overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right); //overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out); overridePendingTransition(R.anim.pop_enter,R.anim.pop_exit); } }); an2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (animation!=null){ if (animation.isRunning()){ animation.stop(); }} } }); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); // toolbar.setNavigationIcon(R.mipmap.ic_launcher); // toolbar.setLogo(R.mipmap.qqq); // toolbar.setTitle("TOOBAR"); // toolbar.setSubtitle("使用"); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { //創建菜單 // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_tool_bar, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { //補間動畫 實例 Animation animation= AnimationUtils.loadAnimation(getBaseContext(),R.anim.anim1); an1.startAnimation(animation); }else if (id == R.id.action_settings1) { //幀動畫 an2.setBackgroundResource(R.drawable.anim2); animation=(AnimationDrawable)an2.getBackground(); animation.start(); }else if (id == R.id.action_settings2) { //屬性動畫 ObjectAnimator oja=ObjectAnimator.ofFloat(an3,"rotation",0,360); oja.setDuration(3000); oja.setRepeatCount(1); //設置插補器 oja.setInterpolator(new BounceInterpolator()); oja.start(); }else if (id == R.id.action_settings3) { ObjectAnimator oja=ObjectAnimator.ofFloat(an4,"alpha",1,0); oja.setDuration(4000); oja.setRepeatCount(1); oja.setRepeatMode(ObjectAnimator.REVERSE); oja.setInterpolator(new LinearInterpolator()); oja.start(); } return super.onOptionsItemSelected(item); } @Override protected boolean onPrepareOptionsPanel(View view, Menu menu) { if (menu != null) { if (menu.getClass() == MenuBuilder.class) { try { Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE); m.setAccessible(true); m.invoke(menu, true); } catch (Exception e) { System.out.print(getClass().getSimpleName() + "onMenuOpened...unable to set icons for overflow menu" + e); } } } return super.onPrepareOptionsPanel(view, menu); }; }
2幀動畫+布局
Android 自定義View時使用TypedArray配置樣式屬性詳細介紹 在自定義v
實現目標 相信大家都知道毛玻璃效果是怎樣的,也可以說是高斯模糊效果。效果圖如下: 這是一個透明,且會對背景進行高斯模糊的效果,看起來就像是毛玻璃一樣,其實不光是側滑
在android開發中只要是列表式風格界面我們幾乎都需要用到List來存放數據,在數量很少的List的話幾乎任何一種循環遍歷方式整體性能都無差別,但是當我們遇到數據量稍大
基於試卷知識點的樹形控件實現demo如下,參考了Hongyang的樹形控件,介紹如下:主要功能:直觀顯示知識點的樹形關系,即某父節點包含一個或N個子節點。 點擊父節點可以