編輯:關於Android編程
實現效果:
項目需求的2個jar包:
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.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); } }
MyAdapter.java:
package com.iwanghang.coordinatordemo; import android.content.Context; import android.support.v7.widget.RecyclerView; import android.view.ViewGroup; import android.widget.TextView; import java.util.List; public class MyAdapter extends RecyclerView.Adapter{ private Context context; private List list; public MyAdapter(Context context, List list) { this.context = context; this.list = list; } public Context getContext() { return context; } public void setContext(Context context) { this.context = context; } public List getList() { return list; } public void setList(List list) { this.list = list; } @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { TextView view = new TextView(context); return new RecyclerView.ViewHolder(view){}; } @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { ((TextView) holder.itemView).setText(list.get(position)); } @Override public int getItemCount() { return list.size(); } }
MyBehavior.java:
package com.iwanghang.coordinatordemo; import android.support.design.widget.CoordinatorLayout; import android.support.v4.view.ViewCompat; import android.view.View; /** * 重寫Behavior的方法 */ public class MyBehavior extends CoordinatorLayout.Behavior { // Behavior 開始滾動 @Override public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, View child, View directTargetChild, View target, int nestedScrollAxes) { return true; } // Behavior 正在滾動 @Override public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, View child, View target, int dx, int dy, int[] consumed) { super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed); if (dy < 0){ // 向上滾動 ViewCompat.animate(child).scaleX(1).scaleY(1).start(); // 顯示控件 }else { // 向下滾動 ViewCompat.animate(child).scaleX(0).scaleY(0).start(); // 隱藏控件 } } }activity_main.xml:
一,使用eclipse打包app內容新建keystore:1、先在eclipse中創建一個新的keystore看詳細圖2、接下來設置一些打包必要參數:3.設置好內容後點擊
百度定位的環境配置1. 獲取密鑰通過開放平台進行應用注冊獲取百度提供的appkey值,這個值用於進行定位時的認證。選擇android端app勾選所有權限進行app的注冊。
Xml概述Java,跨平台的開發語言。Xml,跨平台的傳輸數據。Xml語法標簽語言,類似html。Xml亂碼問題。 1.文檔聲明用來聲明xml的基本屬性,用來指
效果預覽源碼在文章末尾。引文有時候我們的頁面內容過長的時候,滑動到頁面底部用戶再滑動到頂部很麻煩,Android不像iOS可以點擊statusBar回到頂部,一般都是雙擊