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

      

  • 相关阅读:
    Android 学习笔记之WebService实现远程调用+内部原理分析...
    Android学习笔记之Json的使用....
    Android学习笔记之DocumentBuilder的使用....
    Android学习笔记之ExecutorService线程池的应用....
    Android学习笔记之SoftReference软引用...
    windows系统获取进程的pid号并终止
    Linux系统的时间比北京时间慢12个小时的处理方案(将EDT时区改为CST)
    将java的jar包作为windows的服务来启动
    linux初始化shell脚本
    linux中网络部分的总结
  • 原文地址:https://www.cnblogs.com/guanxinjing/p/12213324.html
Copyright © 2011-2022 走看看