【问题标题】:how setup appearance animation to my listView in android?如何在 android 中为我的 listView 设置外观动画?
【发布时间】:2014-11-28 13:54:13
【问题描述】:

我尝试将appearance animation 添加到我的ListView。当我在互联网上搜索时,我终于找到了这个链接。 ListView appearance demo

这是我的MainActivityonCreateView

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.fragment_main);


    ArrayList<String> strings = new ArrayList<String>();
    strings.add("");
    strings.add("");
    strings.add("");
    strings.add("");
    strings.add("");
    strings.add("");

    MyListAdapter mAdapter = new MyListAdapter(this, strings);
    SwingRightInAnimationAdapter swingRightInAnimationAdapter = new SwingRightInAnimationAdapter(mAdapter);

    // Assign the ListView to the AnimationAdapter and vice versa
    ListView myListView = (ListView) findViewById(R.id.myListView);
    swingRightInAnimationAdapter.setAbsListView(myListView);
    myListView.setAdapter(swingRightInAnimationAdapter);
}

但是当我启动这个简单的示例项目时,这个内容会出现错误:

致命异常:主要 java.lang.NoClassDefFoundError: com.nineoldandroids.animation.Animator[]

我下载了 jar 库并在 android studio 的 build.gradle 中使用它

repositories {
mavenCentral()}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/listviewanimations_lib-core_3.1.0.jar')}

如果可能,请帮助我 谢谢

【问题讨论】:

    标签: android listview animation android-studio appearance


    【解决方案1】:

    您在项目中错过了使该库正常工作的 NineOldAndroids jar。你可以在这里下载:https://github.com/JakeWharton/NineOldAndroids/downloads

    正如 Joel 在 cmets 中所说,您不需要将 jars 添加到编译文件中,因为 compile fileTree(dir: 'libs', include: ['*.jar']) 会处理这些。

    您也可以在没有任何 jar 文件的情况下执行此操作。在 android studio 中与这样的存储库同步:

    repositories {
       mavenCentral()
    }
    
    dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      compile 'com.nhaarman.listviewanimations:lib-core:3.1.0@aar'
      compile 'com.nhaarman.listviewanimations:lib-manipulation:3.1.0@aar'
    }
    

    您可以在此页面上检查更多依赖项以编译此库:https://github.com/nhaarman/ListViewAnimations

    【讨论】:

    • 如果你把它们放在 libs 目录中,你真的需要把 jars 放到你的 gradle 文件中吗?这不是compile fileTree(dir: 'libs', include: ['*.jar']) 的用途吗?
    • 我下载该库(jar 文件)并添加到我的依赖项中。但我有一个空指针异常。
    • @Ashkan 请更具体一些。什么样的空指针异常?您是否包含了 NineOldAndroidAndroids jar?您是否从 gradle 构建文件中删除了 compile files('libs/listviewanimations_lib-core_3.1.0.jar')}
    • 不,我只是删除了compile fileTree(dir: 'libs', include: ['*.jar']) 行。我该如何告诉你我的错误类型?
    • 不要删除编译compile fileTree(dir: 'libs', include: ['*.jar']。这就是你的 jar 被初始化的方式。请只删除compile files('libs/listviewanimations_lib-core_3.1.0.jar')
    【解决方案2】:

    您的项目中没有 NineOldAndroids jar。

    下载你需要的jar文件: 库核心 库操作 lib-core-slh 下载最新的 NineOldAndroids .jar 文件

    将 .jar 文件添加到项目的 libs 文件夹中,或将它们作为外部 jar 文件添加到项目的构建路径中。

    请阅读github项目的Readme

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-15
      • 1970-01-01
      相关资源
      最近更新 更多