最近开始看老外写的文章,博客,嗯,不能说比国人写的好,但是感觉看着很爽。真的,一手资料就是爽。

嗯,自己做得不错,第一次看外文博客,我知道自己怎么看的,一句话一句话看下来的,越看越有感觉。

下面这个

https://www.novoda.com/blog/layout-preview-101/

介绍了编写布局时候的技巧,我总结如下:

1.tools 属性:

By using the tools namespace instead of android, while declaring xml attributes, allows you to specify attributes that are going to be used only while in preview. In this case we use tools:text="Title" and tools:src="@drawable/cool_pic"

tools:text 而不是android:text,保证了你所有的内容都只是在预览的时候会出现,程序运行起来不会出现所有tools相关的东西。

包括

tools:visiable

你想显示隐藏的布局,不想来回改代码,这个tools是个不错的选择。

2.自定义控件 preview的时候显示不出来:

In this case View.isInEditMode() saves the day. Use it to check whether you are running on the Preview tool and skip any initialisation that requires dependencies that aren’t available at design time:

    public ImageWithCaptionView(Context context, AttributeSet attrs) {
super(context, attrs); if (!isInEditMode()) {
ArticlesApplication.getInjector().inject(this);
}
}

不错,因为中文的博客我都看烦了,所以去看外文。感觉很不错。

android 布局preview 技巧的更多相关文章

  1. [Android] 布局优化技巧

    看了一些关于优化布局的资料,了解了很多平时不怎么注意的问题,于是把资料整理了一下,一部分内容是翻译来的,一部分是自己理解加上的.每部分内容都有demo,有些资料里的demo比较好的,我就直接拿来用了: ...

  2. android: 动态加载碎片布局的技巧

    虽然动态添加碎片的功能很强大,可以解决很多实际开发中的问题,但是它毕竟只是在 一个布局文件中进行一些添加和替换操作.如果程序能够根据设备的分辨率或屏幕大小在运 行时来决定加载哪个布局,那我们可发挥的空 ...

  3. Android ListView 常用技巧

    Android ListView 常用技巧 Android TextView 常用技巧 1.使用ViewHolder提高效率 ViewHolder模式充分利用了ListView的视图缓存机制,避免了每 ...

  4. 【转】你所不知道的Android Studio调试技巧

    这篇写Android studio debug技巧个人觉得写得不错,转自:http://www.jianshu.com/p/011eb88f4e0d# Android Studio目前已经成为开发An ...

  5. 【转】在Android布局中使用include和merge标签

    内容转自:http://fengweipeng1208.blog.163.com/blog/static/21277318020138229754135/ 在我们开发android布局时,经常会有很多 ...

  6. Android成长日记-Android布局优化

    Android常用布局 1. LinearLayout(线性布局) 2. RelativeLayout(相对布局) 3. TableLayout(表格布局) 4. AbsoluteLayou(绝对布局 ...

  7. css布局左右技巧分享

    无意之间发现左右侧布局很多技巧在里边,接下来分享下实例: <div style="width:40px;height:36px;float:left;overflow:hidden; ...

  8. 【转】Android布局优化之ViewStub

    ViewStub是Android布局优化中一个很不错的标签/控件,直接继承自View.虽然Android开发人员基本上都听说过,但是真正用的可能不多. ViewStub可以理解成一个非常轻量级的Vie ...

  9. Android 布局之LinearLayout

    Android 布局之LinearLayout 1 LinearLayout简介 LinearLayout是线程布局.它包括2个方向(android:orientation):“水平”(horizon ...

随机推荐

  1. So you want to write a desktop app in Python

    So you want to write a desktop app in Python Thomas Kluyver 2014-06-16 23:55 51 Comments Source This ...

  2. 安装xp系统步骤

    下载魔方的绿色软件,使用U盘制作工具 下载xpghost系统. 制作PE,然后把下载的IOS解压后放在U盘 电脑bios设置从u盘启动进入pe系统 运行安装系统

  3. MySQL入门很简单: 15 java访问MySQL数据库

    1. 连接数据库 1.1 下载安装驱动 java通过JDBC(Java Database Connectivity,Java数据库连接)来访问MySQL数据库.JDBC的编程接口提供的接口和类与MyS ...

  4. 使用Atom编写Makedown

    Atom 是 Github 专门为程序员推出的一个跨平台文本编辑器. Markdown是一种可以使用普通文本编辑器编写的标记语言,通过简单的标记语法,它可以使普通文本内容具有一定的格式. 作为一个Gi ...

  5. 816 Ambiguous Coordinates (many cases problem)

    https://www.cnblogs.com/Java3y/p/8846955.html -- link of the problem 816 IDEA: check the dot and int ...

  6. vue中列表的过渡

    <style> .v-enter,.v-leave-to{ opacity: 0; } .v-enter-active,.v-leave-active{ transition: opaci ...

  7. jenkins 执行shell命令出错command not found 和No such file or directory

    [root@localhost usr]# sh test.sh command not found -bash: cd: usr: No such file or directory 这里碰到了一个 ...

  8. 重设SVN 的GNOME keyring [(null)] 的密码

    在ubuntu里如果改了登录密码,那么在使用svn是会要求GNOME keyring [(null)] 的密码: 去掉这个只需:rm -f ~/.gnome2/keyrings/login.keyri ...

  9. Vuex基础-Mutation

    借助官网的一张图,更改 Vuex 的 store 中的状态的唯一方法是提交 mutation.不可以直接对其进行赋值改变.需要注意的是,mutations只能做一些同步的操作. ​​​ 代码结构: ​ ...

  10. centos 6.5 配置nginx环境

    1.卸载系统中默认的php和httpd [root@x ~]# yum remove httpd* php* Loaded plugins: fastestmirror Setting up Remo ...