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

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

  • 相关阅读:
    vue--一些预设属性
    vue--vux框架的使用
    vue--vConsole
    vue--音乐播放器
    vue--使用vue-cli构建项目
    vue--实例化对象
    vue--数据显示模版上
    CSS--交互效果
    Git SSH公钥配置
    gradle配置国内镜像
  • 原文地址:https://www.cnblogs.com/caoxinyu/p/6647754.html
Copyright © 2011-2022 走看看