布局适配
尽量使用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
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。