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!
  • 相关阅读:
    2、容器初探
    3、二叉树:先序,中序,后序循环遍历详解
    Hebbian Learning Rule
    论文笔记 Weakly-Supervised Spatial Context Networks
    在Caffe添加Python layer详细步骤
    论文笔记 Learning to Compare Image Patches via Convolutional Neural Networks
    Deconvolution 反卷积理解
    论文笔记 Feature Pyramid Networks for Object Detection
    Caffe2 初识
    论文笔记 Densely Connected Convolutional Networks
  • 原文地址:https://www.cnblogs.com/poe-blog/p/5669603.html
Copyright © 2011-2022 走看看