zoukankan      html  css  js  c++  java
  • android 布局preview 技巧

    最近开始看老外写的文章,博客,嗯,不能说比国人写的好,但是感觉看着很爽。真的,一手资料就是爽。
    嗯,自己做得不错,第一次看外文博客,我知道自己怎么看的,一句话一句话看下来的,越看越有感觉。
    下面这个
    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);
            }
        }

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

  • 相关阅读:
    python使用thrift访问操作hbase
    js打开新页面
    设计模式
    c# dotfuscator 混淆后无法使用
    SQL server清空数据库日志脚本
    SQlserver 行转列
    SQLServer 脚本测试
    C# HttpWebRequest与HttpWebResponse详解
    反射
    SQl server master
  • 原文地址:https://www.cnblogs.com/caoxinyu/p/6647754.html
Copyright © 2011-2022 走看看