編輯:關於Android編程
代碼不多,就懶得加注釋了.原諒我的懶.
縮略圖獲取那塊,沒有加用線程.可能會在有些低端機上面或者高清的視頻會出現FC的情況.需要的童鞋.自行添加.
附代碼:
package com.tan.videoselectthumbnail; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import com.tan.videoselectthumbnail.R; import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.media.MediaMetadataRetriever; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.util.DisplayMetrics; import android.util.Log; import android.view.GestureDetector; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.RelativeLayout; public class MainActivity extends Activity { private static LinearLayout linearLayout; private static Context context; private RelativeLayout rl_l; private ImageView imageviewPreview,ivw_to2; private GestureDetector mGestureDetector; private RelativeLayout.LayoutParams lp; private Listbitmaps; private int wWidth,iWidth,tWidth; private int arrayWidth[]; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); linearLayout=(LinearLayout) findViewById(R.id.ll); context=this; rl_l=(RelativeLayout) findViewById(R.id.rl_l); imageviewPreview=(ImageView) findViewById(R.id.ivw_to); ivw_to2=(ImageView) findViewById(R.id.ivw_to2); Uri uri=Uri.parse(android.resource:// + getPackageName() + / +R.raw.test); bitmaps=new ArrayList (); getVideoThumbnail(uri); rl_l.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { return (mGestureDetector != null)&& mGestureDetector.onTouchEvent(event); } }); lp=(android.widget.RelativeLayout.LayoutParams) imageviewPreview.getLayoutParams(); mGestureDetector = new GestureDetector(this,new CoverGestureListener()); wWidth=getWindowManager().getDefaultDisplay().getWidth(); } public void onWindowFocusChanged(boolean hasFocus) { iWidth=imageviewPreview.getWidth(); iWidth=wWidth-iWidth; tWidth=iWidth/10; arrayWidth=new int[10]; for(int i=0;i<10;i++){ arrayWidth[i]=tWidth+(i*tWidth); } seekTo(0); super.onWindowFocusChanged(hasFocus); } private void seekTo(float paramFloat) { float f = paramFloat - this.imageviewPreview.getWidth() / 2; if(f<0){ f=0; }if(f>iWidth){ f=iWidth; } lp.leftMargin = ((int) f); for(int i=0;i=f){ imageviewPreview.setImageBitmap(bitmaps.get(i)); ivw_to2.setImageBitmap(bitmaps.get(i)); break; } } this.imageviewPreview.setLayoutParams(this.lp); } private class CoverGestureListener extends GestureDetector.SimpleOnGestureListener { public boolean onDown(MotionEvent e) { seekTo(e.getX()); return true; } public boolean onScroll(MotionEvent e1, MotionEvent e2,float distanceX, float distanceY) { float f = e2.getX(); seekTo(f); return super.onScroll(e1, e2, distanceX, distanceY); } } public void getVideoThumbnail(Uri uri) { Bitmap bitmap=null; MediaMetadataRetriever retriever = new MediaMetadataRetriever(); try { retriever.setDataSource(context, uri); String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); int seconds=Integer.valueOf(time)/1000; int timeS=Integer.valueOf(time)/10; for(int i=1;i<=10;i++){ bitmap=retriever.getFrameAtTime(i*timeS*1000,MediaMetadataRetriever.OPTION_CLOSEST); bitmaps.add(bitmap); addImgView(bitmap); } } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (RuntimeException e) { e.printStackTrace(); } finally { try { retriever.release(); } catch (RuntimeException e) { e.printStackTrace(); } } } public void addImgView(Bitmap bitmap){ SquareImageView imageView=new SquareImageView(context); LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lp.weight=1; imageView.setLayoutParams(lp); imageView.setImageBitmap(bitmap); linearLayout.addView(imageView); } }
因為是demo所以代碼寫的比較亂,將就著看吧.哈哈.
demo鏈接:bin目錄下有apk 可直接拖到模擬器裡面看效果.
模仿支付寶輸入效果,實現很簡單,就是畫個矩形框和圓形,其他的通過組合view來實現所有功能,雖然簡單但是封裝起來,方便以後使用,也分享一下,希望對別人也有點幫助。&nbs
目前,各種App的社區或者用戶曬照片、發說說的地方,都提供了評論功能,為了更好地學習,自己把這個功能實現了一下,做了個小的Demo。首先推薦一款實用的插件LayoutCr
1.修改PagerTabStrip中的背景顏色我們在布局中直接設置background屬性即可: 2.修改指示條的顏色我們可以在java代碼中
Volley的中文翻譯為“齊射、並發”,是在2013年的Google大會上發布的一款Android平台網絡通信庫,具有網絡請求的處理、小圖片的異步