首页 > 移动平台 > 详细

AndroidStudio 添加LayoutCreator插件_自动生成指定布局代码

时间:2020-01-19 14:23:40      阅读:378      评论:0      收藏:0      [点我收藏+]

前言

  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

  

AndroidStudio 添加LayoutCreator插件_自动生成指定布局代码

原文:https://www.cnblogs.com/guanxinjing/p/12213324.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!