java - 如何在 Eclipse Android 开发中使用自定义 View ?

标签 java android eclipse view

我已经下载了一个自定义 View ,我想在我的项目中实现它,但我的困境是:人们使用大术语或暗示我以前从未做过且不了解的操作。

这是我尝试下载的 View :http://androidcustomviews.com/holocolorpicker/

我的问题是:

  1. 如何将 View 导入现有 Eclipse 项目?

  2. 我要修改哪个gradle文件?我有 5 个(build.gradle、gradle.properties、gradlew.file、gradlew.bat、settings.gradle)。

  3. 为什么必须在 gradle 中添加“compile”?这不是开发者可以直接写进去的东西吗?

最佳答案

How do I import a view into an existing Eclipse project?

与其说是“导入 View ”,不如说是导入允许您使用 View 的库,这将在下面解释。

Which gradle file do I modify? There are 5 for me (build.gradle, gradle.properties, gradlew.file, gradlew.bat, settings.gradle).

build.gradle 文件之一。看起来有点像这样

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0-beta1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

这并不像评论所暗示的那样正确。您需要将其添加到另一个,看起来有点像这样

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "xxxx"
        minSdkVersion 23
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.larswerkman:HoloColorPicker:1.5'
}

请参阅我将其与其他依赖项一起添加到底部。

现在,当您执行 gradle 同步时,该库将被下载并自动包含在您的项目中。

之后,您可以像任何其他 View 一样使用 xml 文件中的 View

使用常规 View :

<View
  ..
  .. />

现在,您可以使用此自定义 View :

<com.larswerkman.holocolorpicker.ColorPicker
  ..
  .. />

Why do you have to add 'compile' to the gradle? Isn't this something the developer could just write in it?

我无法回答这个问题,因为这是 gradle 开发团队的选择。但基本上使用 compile 你会说“这里我有这个库,请为我将它编译到项目中”

关于java - 如何在 Eclipse Android 开发中使用自定义 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34351755/

相关文章:

java - gradle:使用不同的jar配置运行两次InstallDist任务

java - jackson 的@JsonIdentityInfo 广度优先

java - 如何在java中为默认 "Object"类创建对象?如您所知,默认情况下每个类都会扩展对象类

java - 在自定义 Unity Android 插件上调用非静态方法

java - 为什么使用 Eclipse Soot 插件中的 Soot 操作时会出现此错误?

java - 用于独立 Swing 项目的 Eclipse Jobs API

java - 如何防止我的方法创建名为 "null"的文件夹

android - setupNotification 返回 "Error already connected"而没有发送连接请求

java - 通过 Eclipse 部署到 Glassfish

java - 如何使用扩展Activity实现onClicklistener的多个列表项点击