0
  • 最佳答案

    都没人回呢。


    代码不给,不知道你怎么写的。

    1153952789488054272  评论     打赏       拉大锯
    • 暖暖的程序员3  回复 @拉大锯
      @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { Log.d(TAG, "onMeasure: ............."); int widthSize = MeasureSpec.getSize(widthMeasureSpec)
      暖暖的程序员3 2021-08-18 09:48   回复 1367312100178915328
    • 暖暖的程序员3  回复 @暖暖的程序员3
      onMeasure里的方法在下面,
      暖暖的程序员3 2021-08-18 09:51   回复 1367312100178915328
  • @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        Log.d(TAG, "onMeasure: .............");
    
        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        Log.d(TAG, "onMeasure: --------------->withSize=="+widthSize);
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        Log.d(TAG, "onMeasure: -------------widthMode=="+widthMode);
        Log.d(TAG, "onMeasure: ---------------->MeasureSpec.EXACTLY="+MeasureSpec.EXACTLY);
        Log.d(TAG, "onMeasure: ---------------->MeasureSpec.UNSPECIFIED="+MeasureSpec.UNSPECIFIED);
        Log.d(TAG, "onMeasure: ---------------->MeasureSpec.AT_MOST="+MeasureSpec.AT_MOST);
        int heightSize = MeasureSpec.getSize(heightMeasureSpec);
        // 测量第一个孩子,也就是内容部分
        // 宽度,跟父控件一样宽。高度有三种情况,如果指定大小,那我们获取到它的大小,直接测量
        // 如果是wrap_content,AT_MOST,如果是match_parent,那就给它大小。
        if (firstChild == null) {
            return;
        }
        LayoutParams contentLayoutParams = firstChild.getLayoutParams();
        int contentHeight=contentLayoutParams.height;
        int contentHeightMeasureSpace;
        if (contentHeight == LayoutParams.MATCH_PARENT) {
            Log.d(TAG, "onMeasure: --------------contentHeight ==MATCH_PARENT");
            contentHeightMeasureSpace = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);
        } else if (contentHeight == LayoutParams.WRAP_CONTENT) {
            Log.d(TAG, "onMeasure: --------------contentHeight ==WRAP_CONTENT");
            contentHeightMeasureSpace = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.AT_MOST);
        } else {
            Log.d(TAG, "onMeasure: --------------contentHeight ==else");
            contentHeightMeasureSpace = MeasureSpec.makeMeasureSpec(contentHeight, MeasureSpec.EXACTLY);
        }
        int a =MeasureSpec.makeMeasureSpec(1080,MeasureSpec.EXACTLY);
    
        firstChild.measure(a, contentHeightMeasureSpace);
        // 拿到内容部分测量以后的高度
        int contentMeasuredHeight = firstChild.getMeasuredHeight();
        // 测量编辑部分,宽度:3/4,高度跟内容高度一样
        int editWidthSize = widthSize * 3 / 4;
        functionView.measure(
                MeasureSpec.makeMeasureSpec(editWidthSize, MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(contentMeasuredHeight, MeasureSpec.EXACTLY)
        );
        // 测量自己
        // 宽就是前面的宽度之和,高度和内容一样
        setMeasuredDimension(widthSize + editWidthSize, contentMeasuredHeight);
    
    }
    


    1367312100178915328  评论     打赏       暖暖的程序员3
相关问题
幻影~ · 安卓
2024-04-26 19:25 2 4
deanhu · AOSP
2024-04-25 21:53 3 10
幻影~ · 提问
2024-04-13 20:13 10 2
幻影~ · 找工作
2024-04-07 10:44 16 2
幻影~ · 问题
2024-03-31 17:20 7 2
TONYGFX · AOSP
2024-03-28 17:11 4 2