編輯:關於android開發
·SharedPreferences
Guide的xml布局界面:
GuideActivity.java
package com.example; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.graphics.Point; import android.view.Menu; import android.view.MotionEvent; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.ImageSwitcher; import android.widget.ImageView; import android.widget.ImageView.ScaleType; import android.widget.ViewSwitcher.ViewFactory; public class GuideActivity extends Activity { private ImageSwitcher mImageSwitcher; private int[] mImgResIds; private int mCurrentImageIndx; private Point mDownPoint = new Point(); private Animation mRight2LeftIn,mRight2leftOut; private String filename = "config"; private String firstRunning = "true"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_guide); SharedPreferences sp = getSharedPreferences(filename, MODE_PRIVATE); String config = sp.getString(firstRunning, null); if(config != null){ Intent intent = new Intent(this, MainActivity.class); startActivity(intent); finish(); } mImageSwitcher = (ImageSwitcher) findViewById(R.id.imageSwitcher); mImgResIds = new int[]{ R.drawable.image01, R.drawable.image02, R.drawable.image03, R.drawable.image04 }; /* * 給使用setFactoru給mImageSwitcher添加兩個子級控件 */ mImageSwitcher.setFactory(new ViewFactory() { @Override public View makeView() { // TODO Auto-generated method stub ImageView v = new ImageView(getApplicationContext()); //這裡是內部類所以不能用this 要用getApplicationContext() v.setScaleType(ScaleType.FIT_XY); v.setImageResource(mImgResIds[mCurrentImageIndx]); return v; } }); mRight2LeftIn = AnimationUtils.loadAnimation(this, R.anim.right2left_in); mRight2leftOut = AnimationUtils.loadAnimation(this, R.anim.right2left_out); } /** * 判斷手勢 */ @Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mDownPoint.x = (int) event.getX(); break; case MotionEvent.ACTION_UP: if(event.getX() - mDownPoint.x >10){ //left ->right :previous } if(mDownPoint.x - event.getX() >10){ // right->left :next if(mCurrentImageIndx < mImgResIds.length - 1){ mCurrentImageIndx++; ((ImageView)mImageSwitcher.getNextView()).setImageResource(mImgResIds[mCurrentImageIndx]); mImageSwitcher.setInAnimation(mRight2LeftIn); mImageSwitcher.setOutAnimation(mRight2leftOut); mImageSwitcher.showNext(); /* * 判斷如果到最後一張圖片就顯示按鈕 * */ if(mCurrentImageIndx == mImgResIds.length - 1){ findViewById(R.id.btn_go_to_main).setVisibility(View.VISIBLE); } } } break; default: break; } return super.onTouchEvent(event); } public void startMain(View v){ SharedPreferences sp = getSharedPreferences(filename, MODE_PRIVATE); Editor editor = sp.edit(); editor.putString(firstRunning, "false"); editor.commit(); Intent intent = new Intent(this,MainActivity.class); startActivity(intent); finish();//引導界面的Activity就會退出,回退棧中也會清除該Activity,點擊回退按鈕也不會回退到引導界面 } }
right2left_in
android:Activity啟動模式之singleTask(一) 先看一下standard啟動模式的說明: 只有一個實例,在同一個應用程序中啟動他的時候,若不存在
狀態可以通過動畫切換的按鈕--第三方開源--TickPlusDrawable,tickplusdrawable Android tickplusdrawab
RecyclerView和PullToRefreshListView的對比,recyclerview項目中上拉刷新和下拉加載一直都是比較常見的;以前一般都是重寫ListV
Android開發學習之路--網絡編程之xml、json 一般網絡數據通過http來get,post,那麼其中的數據不可能雜亂無章,比如我要post一段數據,肯定是要