在程序中如何以dp为单位设置控件的宽和高
来源:互联网 发布:沈晓海花姑子知乎 编辑:程序博客网 时间:2024/06/06 02:19
问:
I'm doing:
button.setLayoutParams(new GridView.LayoutParams(65, 65));
According to the docs the units for the width and height (both 65 in the above) are "pixels". How do you force this to be device independent pixels, or "dp"?
回答:
You'll have to convert it from dps to pixels using the display scale factor.
final float scale = getContext().getResources().getDisplayMetrics().density; int pixels = (int) (dps * scale + 0.5f);
- 在程序中如何以dp为单位设置控件的宽和高
- Android中在代码中设置控件的宽和高
- Android中如何在代码中设置View的宽和高
- 得到屏幕的宽和高,然后在代码里面设置控件的宽和高,加载gif图片
- Android中测量控件的宽和高
- Android中获取控件的宽和高
- Android基础知识4-如何在初始化的时候得到控件的宽和高
- 设置activity为手机屏幕宽和高的方法
- 获取控件的宽和高
- 获取控件的宽和高
- 获取控件的宽和高
- Android在View onCreate时获取控件的宽和高
- wpf 如何动态的设置Grid宽和高
- android 在Activity的OnCreate()方法中如何获取view的宽和高
- fragment中获取控件的宽和高的方法
- ASP.NET中如何获取上传图片的宽和高
- 自定义View中如何获得文本的宽和高
- textView——在代码中动态设置setTextSize,单位为dp
- Ios 入门 ----基本的控件 (二)
- jsp分页原理
- 关注CRM选型的加减法
- 网站加速--服务器编写篇
- 关于本博客
- 在程序中如何以dp为单位设置控件的宽和高
- 获取checkbox选中后表格里的值
- Ios 入门 ----基本的控件 (三)
- FA模块数据流
- Android ROM研究---CyanogenMod源代码下载及编译
- 数据库事务的属性-ACID
- <备忘1002> 我的正版生活,装机列表
- PHP实现常见排序算法
- linux定时器 --setitimer 的用法