1. 当一个ViewGroup中有两个 SurfaceVeiw 时,如surfaceView1, surfaceView2, 要 使sufaceView1 全部显示在下面, 而 surfaceView2 以透明的方式 覆盖在surfaceView1 之上, 如下设置,
surfaceView1.setZOrderOnTop(false);
surfaceView2.setZOrderMediaOverlay(true);
surfaceView2.getHolder().setFormat(PixelFormat.TRANSPARENT);
2.实现Parcelable接口时,成员变量boolean类型的实现:
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。
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-executependingtransactions
4. 下列方法分两个阶段关闭 ExecutorService。第一阶段调用 shutdown 拒绝传入任务,然后等60秒后,任务还没执行完成,就调用 shutdownNow(如有必要)取消所有遗留的任务:
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(); } }