android 代码里设置控件属性
设置字体大小:
setTextSize(TypedValue.COMPLEX_UNIT_PX,22); //22像素
setTextSize(TypedValue.COMPLEX_UNIT_SP,22); //22SP
setTextSize(TypedValue.COMPLEX_UNIT_DIP,22);//22DIP
设置layout_weight:
setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1.0f));
最后的1.0f即是,需要是浮点型的才行
LayoutParams中使用dip作为单位:
final int iv_width = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 22, getResources().getDisplayMetrics());
final int iv_height = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 22, getResources().getDisplayMetrics());
ImageView iv = new ImageView(this);
iv.setLayoutParams(new LinearLayout.LayoutParams(iv_width, iv_height));
iv.setImageResource(R.drawable.check);
iv.setTag(phone_number);
line_pn.addView(iv);
判断ImageView是否是visible的:
if (myImageView.getVisibility() == View.VISIBLE) {
// Its visible
} else {
// Either gone or invisible
}
android 代码里设置控件属性的更多相关文章
- Android在代码中设置控件的drawableLeft,drawableRight,drawableTop,drawableBottom。
根据业务的需要,要在代码中设置控件的drawableLeft,drawableRight,drawableTop,drawableBottom属性. 我们知道在xml中设置的方法为:android:d ...
- Android线程中设置控件
在Android中经常出现多线程中设置控件的值报错的情况,今天教大家封装一个简单的类避免这样的问题,同样也调用实现也非常的方便. 自定义类: /** * Created by wade on 2016 ...
- IOS 制作动画代码和 设置控件透明度
方式1: //animateWithDuration用1秒钟的时间,执行代码 [UIView animateWithDuration:1.0 animations:^{ //存放需要执行的动画代码 s ...
- Android——android必看 各个控件属性(网上看到的文字,觉得挺好的,珍藏了)
属性 值 说明 Android:orientation horizontal/vertical 设置布局水平还是垂直,默认是垂直 android:checked true/false 标记默认选中,如 ...
- Android UI 之TextView控件属性列表
在网上收集到了TextView 的属性,在开发过程中还是挺有用的. android:autoLink 设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接.可选值(non ...
- C#代码中设置 控件的触发器
Style style = new Style(); style.TargetType = typeof(TextBox); MultiDataTrigger trigger = new MultiD ...
- Android 代码里设置ImageView的src和background
设置ImageView的src: image.setImageDrawable(getResources().getDrawable(R.drawable.blackk)); String path= ...
- Android控件属性大全(转)
http://blog.csdn.net/pku_android/article/details/7365685 LinearLayout 线性布局 子元素任意: Tab ...
- Android控件属性大全[整理转载]
控件属性: android属性 Android功能强大,界面华丽,但是众多的布局属性就害苦了开发者,下面这篇文章结合了网上不少资料, 第一类:属性值为true或falseandroid:layout_ ...
随机推荐
- [LeetCode] 381. Insert Delete GetRandom O(1) - Duplicates allowed 常数时间内插入删除和获得随机数 - 允许重复
Design a data structure that supports all following operations in average O(1) time. Note: Duplicate ...
- [LeetCode] 222. Count Complete Tree Nodes 求完全二叉树的节点个数
Given a complete binary tree, count the number of nodes. Note: Definition of a complete binary tree ...
- [LeetCode] 87. Scramble String 搅乱字符串
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...
- idea插件篇之java内存分析工具(JProfiler)
前言在运行java的时候有时候想测试云运行时占用内存情况,这时候就需要使用测试工具查看了.在eclipse里面有 Eclipse Memory Analyzer tool(MAT)插件可以测试,而在i ...
- 为什么我的resharper控件安装之后没有显示
Resharper和Resharper C++有时候会出现,安装之后不显示,VisualStudio菜单栏内找不到的情况,大多数是因为启动VisualStudio的时候没有激活Resharper. 安 ...
- OPTIONS预检请求
OPTIONS预检请求 背景:像后台发送一个post请求,出错,错误代码403(权限验证未通过),查看请求方法变成OPTIONS.检查请求头得知,当前请求token未带上,问题,为什么post请求变成 ...
- POJ 3132 DP+素数筛
Sum of Different Primes Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3684 Accepted ...
- Hbase源码之 compact源码(二)
compact一中介绍了HBASE compact的调度流程,本篇文章主要介绍实际进行compact的过程.先从上文中的chore中接入,在HRegionserver中的compactChecker ...
- gitlab 账号
gitlab 账号 国外版-比较慢 https://gitlab.com/hgnulb 国内版-比较快 https://git.lug.ustc.edu.cn/hglibin github账号 htt ...
- pytest_demo_实战1
1.根目录配置 pytest.ini [pytest] addopts = -p no:warnings 2.更改运行手势,系统配置 file -> setting -> Tools -& ...