AndroidStudio快速实例化控件-插件安装与使用

版权声明:https://blog.csdn.net/qq_40881680 https://blog.csdn.net/qq_40881680/article/details/82012180

下载插件篇

点击左上角的File,然后点击Settings...或者可以直接按Ctrl+Alt+S组合键

之后会进入如下页面,在文本框中输入LayoutCreator,再点击Search in repositories

然后你需要下载插件,点击Install下载

底下有下载进度,等待下载完成!(很快的)

下载完之后,Install按钮会变成如下图这个按钮点击安装

点击后弹出对话框

点击Restare自动重启后就安装成功了!

插件使用篇(举栗)

先举例一个布局xml,一个TextView,两个按钮,分别都给一个id

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

在MainActivity.java中使用插件

首先将光标放在如下图的位置(必须放在这里):

之后点击上方Code,找到你刚下载的那个插件,如图

点击一下,会出一个对话框,直接点击Confirm就可以

然后就会发现所有控件有id的已经快速实例化好了,并且按钮加了点击事件,之后将光标放在报错的位置,按组合键Alt+Enter(回车)进行导包就行,

效果图:

导包:

快速实例化完成了,最后一步:按下图操作

帅的人会点赞,美的人也会点赞,好人也会点赞!

帅的人会点赞,美的人也会点赞,好人也会点赞!

帅的人会点赞,美的人也会点赞,好人也会点赞!

猜你喜欢

转载自blog.csdn.net/qq_40881680/article/details/82012180