編輯:關於Android編程
簡單對比FloatingActionButton和ImageButton的區別:
左邊是ImageButton,右邊是FloatingActionButton:
activity_main.xml:
MainActivity.java:
package com.iwanghang.coordinatordemo; import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.Snackbar; import android.support.design.widget.SwipeDismissBehavior; import android.support.v4.view.ViewCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.TextView; import java.util.ArrayList; import java.util.List; import java.util.Locale; public class MainActivity extends AppCompatActivity { private TextView textView_1; private TextView textView_2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //textView_1 = (TextView) findViewById(R.id.textView_1); textView_2 = (TextView) findViewById(R.id.textView_2); // 手動強轉控件類型 //CoordinatorLayout.LayoutParams params_1 = // (CoordinatorLayout.LayoutParams) textView_1.getLayoutParams(); CoordinatorLayout.LayoutParams params_2 = (CoordinatorLayout.LayoutParams) textView_2.getLayoutParams(); // setBehavior 設置控件的行為 //params.setBehavior(); // SwipeDismissBehavior 實例化滑動刪除行為 SwipeDismissBehaviorbehavior = new SwipeDismissBehavior<>(); // 滑動刪除行為監聽 behavior.setListener(new SwipeDismissBehavior.OnDismissListener() { @Override public void onDismiss(View view) { // 當控件消失 // 在設置控件隱藏之前,其實控件只是透明,還可以滑動回來 view.setVisibility(View.GONE); // 設置控件隱藏 Snackbar.make(view,"刪除控件",Snackbar.LENGTH_LONG) .setAction("撤銷", new View.OnClickListener() { @Override public void onClick(View view) { textView_2.setVisibility(View.VISIBLE); // 設置控件顯示 ViewCompat.animate(textView_2).alpha(1).start(); } }).show(); } @Override public void onDragStateChanged(int state) { // 當控件停止 } }); // 把滑動刪除行為設置到textView控件上 params_2.setBehavior(behavior); RecyclerView recycler_1 = (RecyclerView) findViewById(R.id.recycler_1); List list = new ArrayList<>(); for (int i = 0; i <100 ; i++) { list.add(String.format(Locale.CHINA,"第%03d條數據",i+1)); } recycler_1.setAdapter(new MyAdapter(this,list)); MyBehavior myBehavior = new MyBehavior(); //params_1.setBehavior(myBehavior); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); // 右下角懸浮按鈕 點擊事件監聽 FloatingActionButton findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view,"FloatingActionButton Click",Snackbar.LENGTH_LONG).show(); } }); // 左下角懸浮鈕 點擊事件監聽 ImageButton findViewById(R.id.imageBtn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view,"ImageButton Click",Snackbar.LENGTH_LONG).show(); } }); } }
OpenglES2.0 for Android:各種變換來一波 監聽屏幕事件 在進行各種變換之前,我們先來了解一下如何監聽屏幕的事件。我們下面的變換都需要用立方體來演示,
前言 這段時間在Testerhome上看了一些有關性能測試的帖子,看別人的東西,始終是別人的,只有自己寫一遍才能體會其中的細節,雖然說不要重復造輪子,但是這種基礎的東西
MainActivity.javapackage com.heima52.pullrefresh;import java.util.ArrayList;import co
PullToRefresh是一套實現非常好的下拉刷新庫,它支持:1.ListView2.ExpandableListView3.GridView4.WebView等多種常