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);
            }
        }

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

  • 相关阅读:
    C++ for循环遍历几种写法
    Windwos查看本地局域网内所有的ip方法
    c define
    ssh
    Linux的iptables菜鸟初学
    nc命令的用法
    电脑莫名重启,VS代码丢失的解决办法
    string判断是否是正常的ip格式
    机器学习之推荐算法
    Springboot将mybatis替换为mybatis-plus
  • 原文地址:https://www.cnblogs.com/caoxinyu/p/6647754.html
Copyright © 2011-2022 走看看