Android 杂乱知识点

01、设置状态栏的高度

布局

<View
            android:id="@+id/status_line"
            android:layout_width="match_parent"
            android:layout_height="0dp" />

代码设置

int statusBarHeight = mContext.getResources().getDimensionPixelSize(mContext.getResources().getIdentifier("status_bar_height", "dimen", "android"));
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, statusBarHeight);
        mTitleTop.setLayoutParams(params);

02、RecyclerView 屏蔽滑动 -- 解决ScrollView嵌套RecyclerView获得焦点问题

LinearLayoutManager mLayoutManager = new LinearLayoutManager(mContext) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };

03、解决ScrollView嵌套ListView,进页面时,滑动到底部屏蔽listview的焦点

listview.setFocusable(false);

04、获得自定义View宽高

/**
     * 获取到布局文件的高度和宽度
     *
     * @param child
     */
    private void measureView(View child) {
        ViewGroup.LayoutParams lp = child.getLayoutParams();
        if (lp == null) {
            lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        int childMeasureWidth = ViewGroup.getChildMeasureSpec(0, 0, lp.width);
        int childMeasureHeight;
        if (lp.height > 0) {
            childMeasureHeight = View.MeasureSpec.makeMeasureSpec(lp.height, View.MeasureSpec.EXACTLY);
        } else {
            childMeasureHeight = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
        }
        child.measure(childMeasureWidth, childMeasureHeight);
    }

使用

设置view  measureView(自定义view);
高  childView.getMeasuredHeight()
宽  childView.getMeasuredWidth()

05、Google 推荐使用SparseArray,ArrayMap代替HashMap。

可以提高一倍的性能。

06、反射得到资源

/** 
     * 反射得到资源id 
     *  
     * @param context 
     * @param key 
     *            传入参数,如"R.drawable.ic_launcher", "R.id.textview" 
     * @return 
     */  
    public static int getResourceId(Context context, String key) {  
        String[] keys = key.split("\\.");  
        Resources res = context.getResources();  
        return res.getIdentifier(keys[2], keys[1], context.getPackageName());  
    }  

07、判断多次点击

private static long lastClickTime = 0;  
    private static final long DIFF = 800;  
  
    /** 
     * 判断两次点击的间隔,如果小于diff,则认为是多次无效点击 
     * 
     * @return 
     */  
    public boolean isFastDoubleClick() {  
        long time = System.currentTimeMillis();  
        long timeD = time - lastClickTime;  
        lastClickTime = time;  
        if (timeD < DIFF) {  
            return true;  
        }  
        return false;  
    } 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值