RelativeLayout用代码兑现布局
RelativeLayout用代码实现布局
TextView txt1 = new TextView(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
params.addRule(RelativeLayout.LEFT_OF, 1001);
txt1.setLayoutParams(params);
TextView txt2 = new TextView(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams. WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
txt2.setLayoutParams(params2);
txt2.setText("obj");
txt2.setId(1001);
RelativeLayout layout1 = new RelativeLayout(this);
layout1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
layout1.addView(txt1);
layout1.addView(txt2);
setContentView(layout1);
对应的XML:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TextView
android:id="@+id/leftobj"
android:hint="left of the base"
android:layout_alignParentLeft="true"
android:layout_width="fill_parent"
android:layout_toLeftOf="@+id/base"
android:layout_height="wrap_content"></TextView>
<TextView
android:id="@+id/base"
android:text="obj"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"></TextView>
</RelativeLayout>
RelativeLayout用代码兑现布局的更多相关文章
- android RelativeLayout实现左中右布局
RelativeLayout实现左中右布局 <RelativeLayout android:layout_width="match_parent" android:lay ...
- 【Android开发日记】妙用 RelativeLayout 实现3
段布局
在设计过程中,我们经常会遇到这样的需求: 把一条线3控制,左对齐左控制,右侧控制右对齐,中间控制,以填补剩余空间. 或者一列内放3个控件,上面的与顶部对齐,以下的沉在最底部,中间控件是弹性的.充满剩余 ...
- android中RelativeLayout无法填充ScrollView布局的问题
ScrollView是解决布局过长的情况下使用,一遍其下面会有个顶部布局,我项目里面是RelativeLayout,但是RelativeLayout无论设置 android:layout_height ...
- android 用java代码设置布局、视图View的宽度/高度或自适应
在achat项目中,对话内容的长宽设置为自适应.可是假设文本内容太多,则宽度几乎相同布满,若自己说的和对方说的都非常多内容.则满屏都是文字.则不easy分辨出是来自别人说的还是自己说的.那么须要对本身 ...
- Web前端代码页面布局总结
一. html (1)编码:所有编码均采用xhtml,标签必须闭合,属性值用双引号包括,编码统一为utf-8. (2)语义化:语义化html,正确使用标签. (3)文件命名:命名以中文命名,依实际模 ...
- 在Orchard CMS Theme 用代码定义布局Widgets
因为公司业务需要,经过本人几个月尝试,使用Orchard CMS 开发一个简单的企业门户(地址是http://www.ubof.cn).在刚开始接触Orchard CMS,对于个性化的网页布局不知道怎 ...
- 在Orchard CMS Theme 用代码定义布局Widgets 配置
在上篇中主要详细的叙述了代码的编写,这一篇主要讲解配置.可能有人会有疑问,在上一篇的代码里只有对数据的展示部分的编写,并没有提供数据源.这就是Orchard的强大之处,数据源是通过在后台配置的,那有人 ...
- 响应式自适应布局代码,rem布局
响应式自适应布局代码 首先是先设置根字体大小,PC端一般是16px为根字体,移动端会有不同的,根据情况来设置 js部分 document.querySelector('html').style.fon ...
- RelativeLayout实现左中右布局
<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_co ...
随机推荐
- 深入浅出 妙用Javascript中apply、call、bind【转】
网上文章虽多,大多复制粘贴,且晦涩难懂,我希望能够通过这篇文章,能够清晰的提升对apply.call.bind的认识,并且列出一些它们的妙用加深记忆. apply.call 在 javascript ...
- Java中弹出框的集中方式
1.显示一个错误对话框,该对话框显示的 message 为 'alert': JOptionPane.showMessageDialog(null, "alert", " ...
- SpringCloud分布式开发五大神兽
SpringCloud分布式开发五大神兽 服务发现——Netflix Eureka 客服端负载均衡——Netflix Ribbon 断路器——Netflix Hystrix 服务网关——Netflix ...
- RednaxelaFX写的文章/回答的导航帖
https://www.zhihu.com/people/rednaxelafx/answers http://hllvm.group.iteye.com/group/topic/44381#post ...
- pairRDD中算子reduceByKeyLocally
原型: def reduceByKeyLocally(func: (V, V) => V): Map[K, V] 该函数将RDD[K,V]中每个K对应的V值根据映射函数来运算,运算结果映射到一个 ...
- ph 的使用步骤
Arcanist用户指南Windows Updated 44 Day(s) Ago所有用户 https://phabricator.webfuns.net/book/phabricator/artic ...
- 快速了解Log4J (转)
http://liuzhijun.iteye.com/blog/1746571 ***************************************** Log4J的三个组件: Logger ...
- 检测SqlServer数据库是否能连接的小技巧
有时候可能需要检测下某台机器的服务是不是起来了,或者某台机器的某个库是不是能被连接又不能打开ssms也不想登陆服务器的话就可以用这个方法. 1.在桌面上右键创建个文本,然后改后缀名为udl以后保存(1 ...
- 拷贝内容到eclipse中导致JSP的auto-completion不工作
刚才在编辑JSP文件,有一些东西我懒得敲了,就把一些代码里面拷贝到eclipse的editor中,结果你猜怎么,拷贝进去以后,jsp的auto-completion居然不工作了!(即<%%> ...
- flume sourcetype avro http
flume 当sourcetype=http的时候可以用 curl -X POST -d '[{"headers" :{"APPSTORE" : " ...