1. 當一個ViewGroup中有兩個 SurfaceVeiw 時,如surfaceView1, surfaceView2, 要 使sufaceView1 所有顯示在下面, 而 surfaceView2 以透明的方式 覆蓋在surfaceView1 之上, 以下設置,web
surfaceView1.setZOrderOnTop(false); this
surfaceView2.setZOrderMediaOverlay(true);spa
surfaceView2.getHolder().setFormat(PixelFormat.TRANSPARENT);code
2.實現Parcelable接口時,成員變量boolean類型的實現:orm
public boolean isSelected; public void writeToParcel(Parcel out, int flags) {
out.writeByte((byte) (isSelected ? 1 : 0)); } private LyrPointEntity(Parcel in) { isSelected = in.readByte() != 0; }
3.當在Fragment裏面添加Viewpager,Viewpager由多個Fragment組成,在viewpager的setAdapter時產生錯誤以下:Recursive entry to executePendingTransactions。blog
public class FrgtPagerAdapter extends FragmentPagerAdapter { private ArrayList<Fragment> fragments; public FrgtPagerAdapter(Fragment fragment, ArrayList<Fragment> fragments) { super(fragment.getChildFragmentManager()); this.fragments = fragments; }
於我而言,以前在構造方法裏,super()參數是activity.getSupportFragmentManager(),如上,將其改成
getChildFragmentManager()便可。接口
http://stackoverflow.com/questions/7338823/viewpager-recursive-entry-to-executependingtransactionsci
4. 下列方法分兩個階段關閉 ExecutorService。第一階段調用 shutdown 拒絕傳入任務,而後等60秒後,任務還沒執行完成,就調用 shutdownNow(若有必要)取消全部遺留的任務:get
void shutdownAndAwaitTermination(ExecutorService pool) { pool.shutdown(); // Disable new tasks from being submitted try { // Wait a while for existing tasks to terminate if (!pool.awaitTermination(60, TimeUnit.SECONDS)) { pool.shutdownNow(); // Cancel currently executing tasks // Wait a while for tasks to respond to being cancelled if (!pool.awaitTermination(60, TimeUnit.SECONDS)) System.err.println("Pool did not terminate"); } } catch (InterruptedException ie) { // (Re-)Cancel if current thread also interrupted pool.shutdownNow(); // Preserve interrupt status Thread.currentThread().interrupt(); } }