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模拟器的SD卡中的两种解决方法
    Response JSON数据返回
    jAVA 得到Map价值
    【动态规划】leetcode
    思考互联网分布式系统
    Cocos2d-x数据持久-变更数据
    小程序猿都找到了工作经验的方式
    抄360于Launcher浮动窗口的屏幕显示内存使用情况(改进版)
    vb.net窗口继承(房重建知识汇总)
    Spring该讲座
  • 原文地址:https://www.cnblogs.com/guanxinjing/p/12213324.html
Copyright © 2011-2022 走看看