栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

零散的知识点

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

零散的知识点

一,TextView内容可滚动且有滚动条

参考智能课件,PPTRichView

    private void initView(Context context) {
//        setBackgroundResource(R.drawable.layer_shade_shape);
        textView = new TextView(context);
        LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        if (!TextUtils.isEmpty(textType) && textType.equalsIgnoreCase(PPTConstants.TYPE_MSOTEXTAREA) && !isAiAssistant) {
            //版本判断是为了解决通过java代码的方式实现可滚动的TextView不显示滚动条的问题,重点是用了ViewWithScrollbars
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                ContextThemeWrapper ctw = new ContextThemeWrapper(getContext(), R.style.ViewWithScrollbars);
                textView = new TextView(ctw);
            } else {
                textView = new TextView(getContext(), null, 0, R.style.ViewWithScrollbars);
            }
            textView.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
            textView.setVerticalScrollBarEnabled(true);
            textView.setScrollBarFadeDuration(2000);
            textView.setVerticalFadingEdgeEnabled(false);
            textView.setSingleLine(false);
            textView.setMovementMethod(ScrollingMovementMethod.getInstance());
            layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        }
        textView.setLayoutParams(layoutParams);
        addView(textView);
    }
二,java代码解析设置drawable的xml文件

参考智能课件PPTRichView.java

layer_shade_shape.xml



    
        
            
        
    
    
        
            
        
    

java代码

    private void setRootBackground(String textBackgroundColor, float ratio) {
        try {
            LayerDrawable layerDrawable = (LayerDrawable) getBackground();
            //先还原样式,因为可能有多个PPTRichView用了layer_shade_shape,导致样式已经被设置
            layerDrawable.setLayerInset(1, 0, 0, 0, 0);
            GradientDrawable firstDrawable = (GradientDrawable) layerDrawable.getDrawable(0);
            GradientDrawable secondDrawable = (GradientDrawable) layerDrawable.getDrawable(1);
            firstDrawable.setColor(Color.parseColor("#00000000"));
            secondDrawable.setColor(Color.parseColor("#00000000"));
            //再设置样式
            if (!TextUtils.isEmpty(borderColor) && borderThickness > 0) {
                //乘以2是因为部分手机显示不出来太细的线
                int thickness = (int) (borderThickness * ratio * 2);
                layerDrawable.setLayerInset(1, thickness, thickness, thickness, thickness);
                firstDrawable.setColor(Color.parseColor(borderColor));
            }
            if (!TextUtils.isEmpty(textBackgroundColor)) {
                secondDrawable.setColor(Color.parseColor(textBackgroundColor));
            }
        } catch (Exception e) {
            //不管什么错误,都只给背景色,不考虑边框了
            setBackgroundColor(Color.parseColor(textBackgroundColor));
        }
    }

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/891095.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号