RelativeLayout-代码中成员控件width height
今天需要在代码中动态的设置一个textview的width跟height属性,记录下来。
textview在xml中的布局如下
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/setup_fragment_padding_bottom_vfive"
android:layout_marginLeft="@dimen/setup_fragment_padding_left"
android:layout_marginRight="@dimen/setup_fragment_padding_right"
android:background="@null"
> <!-- Buttons below -->
<!--
In order to show these buttons above the IME keyboard, we need to special case the to
padding to a smaller height.
-->
<TextView
android:id="@+id/previous"
style="@style/accountSetupButtonVfive"
android:layout_width="159dp"
android:layout_height="wrap_content"
android:background="@drawable/email_btn_set"
android:layout_centerVertical="true"
android:text="@string/previous" />
<TextView
android:id="@+id/manual_setup"
style="@style/accountSetupButtonVfive"
android:layout_width="159dp"
android:layout_height="wrap_content"
android:background="@drawable/email_btn_set"
android:layout_centerVertical="true"
android:visibility="gone"
android:text="@string/account_setup_basics_manual_setup_action" /> <TextView
android:id="@+id/next"
style="@style/accountSetupButtonVfive"
android:layout_width="159dp"
android:layout_height="wrap_content"
android:background="@drawable/email_btn_next"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="@string/next" />
</RelativeLayout>
在代码中的更改如下
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams; if (visibility == View.GONE) {
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
mPreviousButton.setBackgroundResource(R.drawable.email_btn_previous_only);
mPreviousButton.setLayoutParams(lp);
}
注意,如果这个控件的layout是LinearLayout,那么你需要使用相应的LinearLayout.LayoutParams
如果你还想调节控件之间的距离,这时候仍然需要借助LinearLayout.LayoutParams
LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
layoutParams1.setMargins(-10, 0, 0, 5);
它就实现了margin属性的设置
RelativeLayout-代码中成员控件width height的更多相关文章
- Android在代码中设置控件的drawableLeft,drawableRight,drawableTop,drawableBottom。
根据业务的需要,要在代码中设置控件的drawableLeft,drawableRight,drawableTop,drawableBottom属性. 我们知道在xml中设置的方法为:android:d ...
- C#代码中设置 控件的触发器
Style style = new Style(); style.TargetType = typeof(TextBox); MultiDataTrigger trigger = new MultiD ...
- PHP代码中input控件使用id无法POST传值,使用name就可以
<html> <head> <title>Example</title> </head> <body> <?php if ...
- C# WinForm中 让控件全屏显示的实现代码
夏荣全 ( lyout(at)163.com )原文 C#中让控件全屏显示的实现代码(WinForm) 有时候需要让窗口中某一块的内容全屏显示,比如视频播放.地图等等.经过摸索,暂时发现两种可行方法, ...
- RelativeLayout中include 控件覆盖重叠的问题
RelativeLayout直接include另一个layout是会把include中的控件与当前layout中的控件覆盖重叠,经过查资料 其中的include标签一定要加上(因为include中不指 ...
- C#中combobox 控件属性、事件、方法
一 .combobox 属性.事件.方法公共属性 名称 说明 AccessibilityObject 获取分配给该控件的 AccessibleObject. AccessibleDefaultActi ...
- MFC中ComboBox控件用法
MFC ComboBox 一.入门篇 ComboBox (组合框)控件很简单,可以节省空间.从用户角度来看,这个控件是由一个文本输入控件和一个下拉菜单组成的.用户可以从一个预先定义的列表里选择一个选项 ...
- CSharpGL(26)在opengl中实现控件布局/渲染文字
CSharpGL(26)在opengl中实现控件布局/渲染文字 效果图 如图所示,可以将文字.坐标轴固定在窗口的一角. 下载 CSharpGL已在GitHub开源,欢迎对OpenGL有兴趣的同学加入( ...
- WPF中Ribbon控件的使用
这篇博客将分享如何在WPF程序中使用Ribbon控件.Ribbon可以很大的提高软件的便捷性. 上面截图使Outlook 2010的界面,在Home标签页中,将所属的Menu都平铺的布局,非常容易的可 ...
随机推荐
- 9 hbase源码系列(九)StoreFile存储格式
hbase源码系列(九)StoreFile存储格式 从这一章开始要讲Region Server这块的了,但是在讲Region Server这块之前得讲一下StoreFile,否则后面的不好讲下去 ...
- Spring 容器(一)
Source null instanceof Object 语法是正确的 Source定义得到输入流的方法 Resource继承Source,定义判断流是否存在.是否打开等方法 BaseResourc ...
- 石子合并 (区间DP)
一.试题在一个园形操场的四周摆放N堆石子(N≤100),现要将石子有次序地合并成一堆.规定每次仅仅能选相邻的两堆合并成新的一堆,并将新的一堆的石子数.记为该次合并的得分.编一程序.由文件读入堆数N及每 ...
- Qt编译OpenGL程序遇到的问题
软件版本号: Qt 4.8.5 依照网上的例程(http://www.qiliang.net/old/nehe_qt/lesson01.html),跑了一下基于Qt Creator的OpenGL.因为 ...
- 惊叹计算机运行速度的提升---以n Queens 问题为例
1 介绍 实现了书<Data Structures and Program design in C++>(Robert L. Kruse and Alexander J. Ryba, 20 ...
- Centos7.4 modsecurity with nginx 安装
1.准备: 系统环境:Centos7.4 软件及版本: nginx:OpenResty1.13.6.1 ModSecurity:ModSecurity v3.0.0rc1 (Linux) modsec ...
- 如何卸载visualsvn for visual studio
新入职的公司,电脑上的visual studio已经安装了visualsvn 尝试在tools-->extensions and updates中卸载 但是uninstall按钮是被禁用掉的 谷 ...
- apiCloud手动检测更新
有时候需要给用户一个自主的权利,自主检测app是否是最新版本. 如何实现? 1.点击调用接口,检测是否有更新. 默认APICloud会自动检测版本更新,用户也可以在config.xml里配置autoU ...
- thinkphp5项目--企业单车网站(七)
thinkphp5项目--企业单车网站(七) 项目地址 fry404006308/BicycleEnterpriseWebsite: Bicycle Enterprise Websitehttps:/ ...
- Material Design控件使用学习 TabLayout+SwipeRefreshlayout
效果: Tablayout有点类似之前接触过的开源ViewPagerIndicator,将其与viewpager绑定,可实现viewpager的导航功能. SwipeRefreshLayout是官方出 ...