美文网首页
一些布局优化技巧

一些布局优化技巧

作者: 山岭巨人郭敬明 | 来源:发表于2016-12-19 09:44 被阅读0次

实现下图效果只需一个TextView

Paste_Image.png
<?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"> 
<TextView android:drawableLeft="@drawable/icon_1" 
    android:drawableRight="@drawable/icon_4" 
    android:drawablePadding="10dp" 
    android:paddingLeft="10dp" 
    android:paddingRight="10dp" 
    android:textSize="16sp" 
    android:text="我的卡券" 
    android:background="@color/white" 
    android:gravity="center_vertical" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" />
</LinearLayout>

动态设置文本与图片相对位置时,常用到如下方法:
setCompoundDrawables(left, top, right, bottom)
setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom)
两者有些区别:setCompoundDrawables 画的drawable的宽高是按drawable.setBound()设置的宽高,所以才有The Drawables must already have had setBounds(Rect) called.
使用之前必须使用Drawable.setBounds设置Drawable的长宽。
setCompoundDrawablesWithIntrinsicBounds是画的drawable的宽高是按drawable固定的宽高,所以才有The Drawables' bounds will be set to their intrinsic bounds.
即通过getIntrinsicWidth()与getIntrinsicHeight()获得

LinearLayout添加分割线
LinearLayout有两个属性
1、Android:divider="@drawable"
drawable可以是图片文件,也可以是xml绘制的shape。
使用shape的时候一定要添加<size> ,一定要添加颜色,即使是透明,例如:

<?xml version="1.0" encoding="utf-8"?>  
<shape xmlns:android="http://schemas.android.com/apk/res/android">  
    <solid android:color="@color/account_line" />  
    <size android:height="1px" />  
</shape>  

2、

android:showDividers = "middle|end|beginning|none"

middle 在每一项中间添加分割线
end 在整体的最后一项添加分割线
beginning 在整体的最上方添加分割线
none 无

使用.9图
先将图片名加上.9,如原图名为ic_launcher.png,则改为ic_launcher.9.png
双击打开后点击左下角

Paste_Image.png Paste_Image.png

就可以使用了

EditText样式
1.更改光标颜色:可设置颜色或图片

android:textCursorDrawable="@color/colorPrimary"
android:backgroundTint="#9bd435" <!--下划线颜色-->
android:textColorHighlight="#9bd435" <!--选中文字背景色-->

3.使用Material Design主题属性
首先了解一下Material Design 各个属性。这里有张在网上找来的图,此图一目了然。

Paste_Image.png

那么其实就简单了,在我们的主题中加入colorAccent
即可。

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorAccent">#9bd435</item>
</style>

效果图:


Paste_Image.png

相关文章

  • Android开发遇到的问题

    1.splash(欢迎页) 里边做的事 2.布局优化技巧布局优化技巧

  • 一些布局优化技巧

    实现下图效果只需一个TextView 动态设置文本与图片相对位置时,常用到如下方法:setCompoundDraw...

  • android布局优化

    android布局优化的目标: 使屏幕绘制低延迟 保证流程稳定的帧率来避免卡顿 优化布局的技巧: 减少布局层次下图...

  • 性能优化技巧知识梳理(2) - 内存优化

    一、前言 对于应用中的内存优化,和布局优化类似,也有很多的技巧,这里我们分为以下几方面来总结: Java优化技巧 ...

  • 布局优化技巧

    布局技巧 在Android开发过程中,我们会遇到很多的问题,随着UI界面越来越多,布局的重复性、复杂度也随之增加,...

  • Android画布剪裁函数clipRect详解

    最近因为在总结一些优化UI布局的技巧,在解决过度绘制的时候很多都用到了clipRect函数来进行自定义控件的优化。...

  • Android布局优化

    本文主要记录Android布局优化的一些小技巧Android中,如果一个View树的高度太高,就会严重影响测量,布...

  • Android布局优化(一)LayoutInflate — 从布

    目录 前言 最近打算写一些Android布局优化相关的文章,既然要进行布局优化,就要先了解布局加载原理,才能知道有...

  • Android布局优化技巧

    一.总体原则:减少布局层次,加快渲染速度 当线性布局LinearLayout和相对布局都能使用时,优先使用线性布局...

  • 你会经常遇见的android性能优化方面知识总结

    项目源码 目录 布局优化 绘制优化 内存泄漏优化 ListView和Bitmap优化 布局优化 减少布局文件的层级...

网友评论

      本文标题:一些布局优化技巧

      本文链接:https://www.haomeiwen.com/subject/wdazmttx.html