zoukankan      html  css  js  c++  java
  • AndroidStudio 添加LayoutCreator插件_自动生成指定布局代码

    前言

      LayoutCreator插件可以快速帮助生成xml布局中的代码,但是有以下自动生成规则:

    1. 自动遍历目标布局中所有带id的文件, 无id的不会识别处理
    2. 控件生成的变量名默认为id名称, 可以在弹出确认框右侧的名称输入栏中自行修改
    3. 所有的Button或者带clickable=true的控件, 都会自动在代码中生成setOnClickListener相关代码
    4. 所有EditText控件, 都会在代码中生成非空判断代码, 如果为空会提示EditText的hint内容, 如果hint为空则提示xxx字符串不能为空字样, 最后会把所有输入框的验证合并到一个submit方法中
    5. 会自动识别布局中的include标签, 并读取对应布局中的控件

    使用效果

    需要生成的xml

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MyLayoutDemoActivity">
    
        <Button
            android:id="@+id/button1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="1"
            app:layout_constraintBottom_toTopOf="@+id/textView"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    
    
        <TextView
            android:id="@+id/textView"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="content"
            android:gravity="center"
            app:layout_constraintTop_toBottomOf="@id/button1"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent" />
    
    </androidx.constraintlayout.widget.ConstraintLayout>

    自动生成的代码

    如何添加?

      第一步

        在Android studio 的菜单栏找到 File > Settings 点击

      第二步

      找到Plugins , 在搜索栏输入LayoutCreator 回车搜索,然后在点击安装 LayoutCreator,安装完成后需要重启Android studio

      

    如何使用?

      方式一

       1.将鼠标点击到指定Activity的Java文件的R.layout.xxxxx的布局代码上

      2.在Android studio 菜单栏点击 code 找到 LayoutCreator 点击,就可以进入创建页面了,选择你需要的命名与需要生成的View在点击 Confirm

      方式二

        1.将鼠标点击到指定Activity的Java文件的R.layout.xxxxx的布局代码上

        2.直接A/t + Insert  按键,找到LayoutCreator 点击

    end

      

  • 相关阅读:
    第三百三十二节,web爬虫讲解2—Scrapy框架爬虫—Scrapy使用
    trim思考
    国王验毒酒问题
    有人在群里问mysql如何选择性更新部分条件的问题
    有人在群里问 20180222055怎么转20180222-055 这样的问题
    如何下载腾讯视频的视频转为MP4常用格式视频
    天气预报的大雪真的下了
    群友面试的问题 我搞笑的帮忙回答一下
    电台大神打油诗
    ajax简单手写了一个猜拳游戏
  • 原文地址:https://www.cnblogs.com/guanxinjing/p/12213324.html
Copyright © 2011-2022 走看看