前言

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 的样式的更多相关文章

  1. android自定义控件,动态设置Button的样式

    原文  http://www.cnblogs.com/landptf/p/4562203.html 今天来看一个通过重写Button来动态实现一些效果,如圆角矩形.圆形.按下改变字体,改变背景色,改变 ...

  2. Android按钮的各个样式设置

    安卓开发学习之014 Button应用详解(样式.背景.按钮单击.长按.双击.多击事件) 一.Button简介 按钮也是继承自TextView 二.XML定义方法 <Button android ...

  3. Android下用程序的方法为ListView设置分割线Divider样式

    使用XML的时候可以使用android:divider属性为ListView设置分割线的样式(颜色或者资源文件),而在Java代码中默认提供的方法 listView.setDivider() 却只支持 ...

  4. 巧用android:divider属性设置LinearLayout中元素之间的间隔

    如上图,要想实现3个button线性排列并且使它们的大小相同.间隔相等.而且整体填充满整个linearlayout,我们一般的做法是在每两个button之间放一个固定宽度的view,然后设置butto ...

  5. Android 自定义RadioButton的样式

    Android 自定义RadioButton的样式 我们知道Android控件里的button,listview可以用xml的样式自定义成自己希望的漂亮样式. 最近用到RadioButton,利用xm ...

  6. Android中实现全屏、无标题栏的两种办法(另附Android系统自带样式的解释)

    在进行UI设计时,我们经常需要将屏幕设置成无标题栏或者全屏.要实现起来也非常简单,主要有两种方法:配置xml文件和编写代码设置. 1.在xml文件中进行配置 在项目的清单文件AndroidManife ...

  7. android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams

      http://blog.csdn.net/lilu_leo/article/details/11952717 有时候需要在在代码中设置LayoutParams,自己为一个FrameLayout设置 ...

  8. 通过Spannable对象设置textview的样式

    通过Spannable对象我们可以设置textview的各种样式,其功能十分强大.通过SpannableString和它的setSpan(Object what, int start, int end ...

  9. Android中无标题样式和全屏样式学习

    在进行UI设计时,我们经常需要将屏幕设置成无标题栏或者全屏.要实现起来也非常简单,主要有两种方法:配置xml文件和编写代码设置. 1.在xml文件中进行配置 在项目的清单文件AndroidManife ...

随机推荐

  1. Leetcode | Find Minimum in Rotated Sorted Array I && II

    Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...

  2. 给RecyclerView实现的GridView加上HeaderView和FooterView

    给RecyclerView设置布局管理器 GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3); 写适配器,添加子项 ...

  3. P1073 最优贸易

    #include <bits/stdc++.h> using namespace std; const int maxn = 100005; int head1[maxn], head2[ ...

  4. python中的构造函数和析构函数

    python中的特殊方法,其中两个,构造函数和析构函数的作用: 比说“__init__”这个构造函数,具有初始化的作用,也就是当该类被实例化的时候就会执行该函数.那么我们就可以把要先初始化的属性放到这 ...

  5. js鲸鱼

    <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...

  6. butterknife异常提示:attribute value must be constant

    就是因为你的android工程是lib类型的 如: apply plugin: 'com.android.library' android { compileSdkVersion 23 buildTo ...

  7. java math library

    https://github.com/jroyalty/jglm https://github.com/JOML-CI/JOML

  8. 一个编程小白,如何入门APP软件开发领域?

    近些年,互联网创业火得不得了!一时间,满世界都在招做App软件开发的专业人员.从大众角度来看,学编程,写代码,是一件非常困难的事情.但是,App开发人员的工资那么诱人,让很多小白也跃跃欲试想学一下.那 ...

  9. MVC项目实践,在三层架构下实现SportsStore,从类图看三层架构

    在"MVC项目实践,在三层架构下实现SportsStore-02,DbSession层.BLL层"一文的评论中,博友浪花一朵朵建议用类图来理解本项目的三层架构.于是就有了本篇: I ...

  10. 正则表达式获取字符串中的img标签中的url链接

    废话不多说直接看代码 JavaScript中的代码: var re = /src=\"([^\"]*?)\"/i; var arr = str.match(re); if ...