App适配

作者: Neo_duan | 来源:发表于2018-01-12 22:47 被阅读177次

布局适配

尽量使用wrap_content、match_parent、weight padding
使用相对布局
.9图片应用
动态获取屏幕宽高
根据Android系统各个版本差异性,进行代码适配工作(权限、文件共享)
百分比布局的引用
布局下建立各个屏幕尺寸的値(不建议,不能包含所有机型)

字体适配

方式1:
    使用dp
方式2:
    使用代码设置
    private void adjustTvTextSize(TextView tv, int maxWidth, String text) {
    int avaiWidth = maxWidth - tv.getPaddingLeft() - tv.getPaddingRight() - 10;

    if (avaiWidth <= 0) {
        return;
    }

    TextPaint textPaintClone = new TextPaint(tv.getPaint());
    // note that Paint text size works in px not sp
    float trySize = textPaintClone.getTextSize();

    while (textPaintClone.measureText(text) > avaiWidth) {
        trySize--;
        textPaintClone.setTextSize(trySize);
    }

    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, trySize);
    }

方式3(推荐方式):
    固定zit字体大小不随系统变化(手机QQ、微信)
    在工程的Application或BaseActivity中添加下面的代码
    
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        if (newConfig.fontScale != 1)//非默认值
            getResources();    
        super.onConfigurationChanged(newConfig);
    }
    
    @Override
    public Resources getResources() {
         Resources res = super.getResources();
         if (res.getConfiguration().fontScale != 1) {//非默认值
            Configuration newConfig = new Configuration();       
            newConfig.setToDefaults();//设置默认        
            res.updateConfiguration(newConfig, res.getDisplayMetrics()); 
         }    
         return res;
    }

软键盘适配

https://www.jianshu.com/p/640bac6f58ab

相关文章

网友评论

      本文标题:App适配

      本文链接:https://www.haomeiwen.com/subject/ylsqoxtx.html