【Android】设置 LinearLayout 的样式
前言
LinearLayout是最常用的控件之一,主要是用来进行排版布局,本人介绍如何给LinearLayout 增加边框样式,在增加样式之前的效果如下:
可以看得出来,每个LinearLayout几乎都连接在一起,视觉效果较差,下面我们为此编写一个样式,如同CSS样式表:
解决方法
1.在res文件夹中新建一个 android 的 xml 文件,命名为“linearlayout_boder”,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#FFFFFF" /> <stroke
android:width="0.1dp"
android:color="#DDDDDD" /> <padding
android:bottom="1dp"
android:left="0.5dp"
android:right="0.5dp"
android:top="0dp" />
</shape>
2.在需要用到此样式的地方增加如下代码:
android:background="@drawable/linearlayout_boder"
3.完整代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
> <LinearLayout
android:layout_width="match_parent"
android:layout_height="28dp"
android:background="@drawable/linearlayout_boder"
> <TextView
android:id="@+id/TextView04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="9"
android:text=" WLAN" /> <ImageView
android:id="@+id/ImageView04"
android:layout_width="28dp"
android:layout_height="match_parent"
android:layout_weight="0.38"
android:src="@drawable/onblack" />
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="28dp"
android:background="@drawable/linearlayout_boder"> <TextView
android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="9"
android:text=" 蓝牙" /> <ImageView
android:id="@+id/ImageView03"
android:layout_width="28dp"
android:layout_height="match_parent"
android:layout_weight="0.38"
android:src="@drawable/onblack" />
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="28dp"
android:background="@drawable/linearlayout_boder"> <TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="9"
android:text=" 省电模式" /> <ImageView
android:id="@+id/ImageView02"
android:layout_width="28dp"
android:layout_height="match_parent"
android:layout_weight="0.38"
android:src="@drawable/onblack" />
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="28dp"
android:background="@drawable/linearlayout_boder"> <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="9"
android:text=" 重力感应" /> <ImageView
android:id="@+id/imageView1"
android:layout_width="28dp"
android:layout_height="match_parent"
android:layout_weight="0.38"
android:src="@drawable/onblack" /> </LinearLayout> </LinearLayout>
最终效果
【Android】设置 LinearLayout 的样式的更多相关文章
- android自定义控件,动态设置Button的样式
原文 http://www.cnblogs.com/landptf/p/4562203.html 今天来看一个通过重写Button来动态实现一些效果,如圆角矩形.圆形.按下改变字体,改变背景色,改变 ...
- Android按钮的各个样式设置
安卓开发学习之014 Button应用详解(样式.背景.按钮单击.长按.双击.多击事件) 一.Button简介 按钮也是继承自TextView 二.XML定义方法 <Button android ...
- Android下用程序的方法为ListView设置分割线Divider样式
使用XML的时候可以使用android:divider属性为ListView设置分割线的样式(颜色或者资源文件),而在Java代码中默认提供的方法 listView.setDivider() 却只支持 ...
- 巧用android:divider属性设置LinearLayout中元素之间的间隔
如上图,要想实现3个button线性排列并且使它们的大小相同.间隔相等.而且整体填充满整个linearlayout,我们一般的做法是在每两个button之间放一个固定宽度的view,然后设置butto ...
- Android 自定义RadioButton的样式
Android 自定义RadioButton的样式 我们知道Android控件里的button,listview可以用xml的样式自定义成自己希望的漂亮样式. 最近用到RadioButton,利用xm ...
- Android中实现全屏、无标题栏的两种办法(另附Android系统自带样式的解释)
在进行UI设计时,我们经常需要将屏幕设置成无标题栏或者全屏.要实现起来也非常简单,主要有两种方法:配置xml文件和编写代码设置. 1.在xml文件中进行配置 在项目的清单文件AndroidManife ...
- android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
http://blog.csdn.net/lilu_leo/article/details/11952717 有时候需要在在代码中设置LayoutParams,自己为一个FrameLayout设置 ...
- 通过Spannable对象设置textview的样式
通过Spannable对象我们可以设置textview的各种样式,其功能十分强大.通过SpannableString和它的setSpan(Object what, int start, int end ...
- Android中无标题样式和全屏样式学习
在进行UI设计时,我们经常需要将屏幕设置成无标题栏或者全屏.要实现起来也非常简单,主要有两种方法:配置xml文件和编写代码设置. 1.在xml文件中进行配置 在项目的清单文件AndroidManife ...
随机推荐
- token原理
token原理1.和session有很大关系哦. jsp生成表单时,在表单中插入一个隐藏<input>字段,该字段就是保存在页面端的token字符串,同时把该字符串存入session中.等 ...
- bootstrap全局CSS样式学习
参考http://v3.bootcss.com/css/,根据自己的记忆进行的复述,加深记忆. 首先介绍bootstrap全局CSS样式 只通过使用bootstrap.css,即可获得统一的样式设置. ...
- fight
为啥用block copy. 从栈到拷贝到堆 循环引用,控制器引用block. block里面调用 self self引用控件,控件引用block,block里面引用self http://www. ...
- 8 ways rich people view the world differently than the average person
Self-made millionaire Steve Siebold spent 26 years interviewing some of the wealthiest people in the ...
- wp插件
- Selenium2学习-038-firefox、webdriver版本不对称问题解决:org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055
今天有个朋友在群里问,为何脚本运行不通过,其脚本操作步骤简单描述如下: 1.启动火狐浏览器 2.打开百度 3.查询框输入关键字 4.点击按钮[百度一下] 脚本挺简单的,其给出的应用报错信息如下所示: ...
- Android 高德地图No implementation found for long com.autonavi.amap.mapcore.MapCore
此篇博客最后更新时间写自2016.5.18.当下高德地图jar版本为3.3.1. 使用高德地图碰到此问题,纠结许久(接近4个多小时). 记录在此,希望遇到相同问题的读者可以有所借鉴. 错误截图: 导致 ...
- zabbix监控交换机
zabbix可以通过snmp协议监控交换机 前提: 交换机需要开启snmp协议,通过snmpwalk 可以抓取到数据就可以了 snmpwalk -v 2c -c public *.*.*.* 1.创建 ...
- oracle创建、删除账户
1.创建 /*第1步:创建表空间 */create tablespace xybi datafile 'E:\oracle\oradata\zzxe\xybi_d01' size 100M ; /*第 ...
- [BS-30] 你真的会用storyboard开发吗?
你真的会用storyboard开发吗? 随着苹果大屏手机的推出,苹果公司马上推出了屏幕适配的一些东西Constraints and Size Classes同时,在开发项目时候,是使用sb还是写代 ...