zoukankan      html  css  js  c++  java
  • ButterKnifeZelezny简单使用教程

     
    zelezny_animated.gif
     
    一,配置butterknife
     
    Configure your project-level build.gradle to include the 'android-apt' plugin:
    
    buildscript {
      repositories {
        mavenCentral()
       }
      dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
      }
    }
    Then, apply the 'android-apt' plugin in your module-level build.gradle and add the Butter Knife dependencies:
    
    apply plugin: 'android-apt'
    
    android {
      ...
    }
    
    dependencies {
      compile 'com.jakewharton:butterknife:8.2.1'
      apt 'com.jakewharton:butterknife-compiler:8.2.1'
    }
    二,安装ButterKnifeZelezny插件
           
    File -> Seting -> Plugins -> Browser Responsities ->Butterknife Zelezny
     
    三,使用插件时xml中的布局写法
    /**
     * 首页选择
     */
    public class MainListActivity extends AppCompatActivity {
    
        @BindView(R.id.marquee_tv)
        TextView mMarqueeTv;
        @BindView(R.id.more_tv)
        TextView mMoreTv;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main_list);
            ButterKnife.bind(this);
        }
    
        @OnClick({R.id.marquee_tv, R.id.more_tv})
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.marquee_tv:
                    break;
                case R.id.more_tv:
                    break;
            }
        }
    }
    

       

    像做到如上效果还需两步:
    step 1> 设置ButterKnife Zelezny
     
     
    step 2> xml布局变量写法 
     
    activity_main_list.xml
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:orientation="vertical"
        >
        <TextView
            android:id="@+id/marquee_tv"
            style="@style/item_main_menu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Marquee demo"
            />
        <TextView
            android:id="@+id/more_tv"
            style="@style/item_main_menu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="More demo"
            />
    </LinearLayout>
    

      

     
    现在请在Activity的布局文件名字上面右键Generate->Generate ButterKnife Injection 
    Enjoys!
  • 相关阅读:
    CentOS 7 配置hadoop(五) 配置sqoop(伪分布)
    CentOS 7 配置hadoop(四) 配置hive(伪分布)
    CentOS 7 配置hadoop(三) 配置hbase(伪分布)
    java高级之NIO
    字符编码与序列化
    java高级之IO流 -2
    java中的值传递和引用传递
    事务相关知识点
    mybatis中批量更新sql语句,trim、foreach标签,varchar定义理解
    java IO流之File类的使用
  • 原文地址:https://www.cnblogs.com/poe-blog/p/5669603.html
Copyright © 2011-2022 走看看