編輯:關於Android編程
1、在GridView 中我們會遇到當選中某個Item 時想讓它處於高亮或者是放大的操作,我們只需要在setOnItemClickListener() 方法中把相應的position 給傳過去。
package com.example.sgridview; import java.util.ArrayList; import java.util.List; import android.annotation.SuppressLint; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.ImageView; import android.widget.ImageView.ScaleType; public class MainActivity extends Activity { private GridView gridView; private MyAdapter adapter = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); lists.add(R.drawable.ic_launcher); lists.add(R.drawable.ic_launcher); lists.add(R.drawable.ic_launcher); this.gridView = (GridView) this.findViewById(R.id.gridView); adapter = new MyAdapter(); this.gridView.setAdapter(adapter); this.gridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView> arg0, View arg1, int id, long arg3) { // TODO Auto-generated method stub MyAdapter ad = (MyAdapter) arg0.getAdapter(); ad.setNotifyDataChange(id); } }); } private Listlists = new ArrayList (); private class MyAdapter extends BaseAdapter { private int selectPic = -1; @Override public int getCount() { // TODO Auto-generated method stub return lists.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return lists.get(position); } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } public void setNotifyDataChange(int id) { selectPic = id; super.notifyDataSetChanged(); } @SuppressLint("NewApi") @Override public View getView(int position, View view, ViewGroup arg2) { ImageView img = new ImageView(MainActivity.this); img.setBackgroundResource(lists.get(position)); if (selectPic == position) { Animation testAnim = AnimationUtils.loadAnimation(MainActivity.this, R.anim.anim); img.startAnimation(testAnim); } else { // the rest img.setScaleType(ScaleType.CENTER_INSIDE); } return img; } } }
效果圖自定義代碼public class BezierView extends View { Paint paint;//畫筆 Path path;//路徑
本文實例講述了Android編程單元測試。分享給大家供大家參考,具體如下:完整實例代碼代碼點擊此處本站下載。本文是在上一篇文章《java編程之單元測試(Junit)實例分
實現原理(1)首先獲得下載文件的長度,然後設置本地文件的長度。(2)根據文件長度和線程數計算每條線程下載的數據長度和下載位置。如:文件的長度為6M,線程數為3,那麼,每條
序言上一篇中我們介紹了幾個簡單的新UI控件,相信很多小伙伴對Materil Design的視覺效果有了一定的了解,今天我們就繼續介紹其他幾個控件的玩兒法,讓我們一探Mat