粘性网格标题无法在某些Android版

时间:2017-04-14 09:34:52

标签: android android-layout android-studio gradle

我正在使用带有以下应用Gradle依赖项的Sticky网格标题。

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')

    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.tonicartos:stickygridheaders:1.0.1'
    testCompile 'junit:junit:4.12'

}

构建工具版本

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.stickyheader"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 8
        versionName '3'
        multiDexEnabled true
    }

 }

Curruntly使用android studio 2.2.3。 在我更新Android studio之前,它适用于所有设备,也适用于kitkat版本。 在某些设备中,特别是在kitkat之下崩溃,以及kitkat版本代码正常运行。

在以下版本的kitkat设备中,我收到此错误, 堆栈跟踪

  

04-14 10:32:13.520 24869-24869 / com.example.stickyheader   E / AndroidRuntime:致命异常:主要                                                                                java.lang.RuntimeException:无法启动活动   ComponentInfo {com.example.stickyheader / com.example.stickyheader.CustomerEventDetailActivity}:   android.view.InflateException:二进制XML文件行#62:错误   膨胀班   com.tonicartos.widget.stickygridheaders.StickyGridHeadersGridView                                                                                    在   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2067)                                                                                    在   android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2092)                                                                                    在android.app.ActivityThread.access $ 600(ActivityThread.java:133)                                                                                    在   android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1203)                                                                                    在android.os.Handler.dispatchMessage(Handler.java:99)                                                                                    在android.os.Looper.loop(Looper.java:137)                                                                                    在android.app.ActivityThread.main(ActivityThread.java:4794)                                                                                    at java.lang.reflect.Method.invokeNative(Native Method)                                                                                    在java.lang.reflect.Method.invoke(Method.java:511)                                                                                    在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:789)                                                                                    在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)                                                                                    at dalvik.system.NativeStart.main(Native Method)                                                                                 引起:android.view.InflateException:二进制XML文件行#62:   膨胀类时出错   com.tonicartos.widget.stickygridheaders.StickyGridHeadersGridView                                                                                    在   android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)                                                                                    在android.view.LayoutInflater.rInflate(LayoutInflater.java:746)                                                                                    在android.view.LayoutInflater.inflate(LayoutInflater.java:489)                                                                                    在android.view.LayoutInflater.inflate(LayoutInflater.java:396)                                                                                    在android.view.LayoutInflater.inflate(LayoutInflater.java:352)                                                                                    在   android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288)                                                                                    在   android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)

另外这是我的粘性网格标题的Xml代码。

 <com.tonicartos.widget.stickygridheaders.StickyGridHeadersGridView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/gridViewCustomer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:animateLayoutChanges="true"
        android:choiceMode="singleChoice"
        android:columnWidth="250dp"
        android:fastScrollEnabled="true"
        android:horizontalSpacing="1dp"
        android:numColumns="auto_fit"
        android:stretchMode="columnWidth"
        android:verticalSpacing="5dp"/>

似乎它会给出错误,因为appCompact版本在build.gradle中依赖于defhere(我不确定)。

启用以处理此错误。

我也试着评论这种依赖性

 compile 'com.android.support:appcompat-v7:25.3.1'

但没有工作。

谢谢你:)

3 个答案:

答案 0 :(得分:2)

这似乎是一个图书馆问题。您发布的堆栈跟踪也没有关于崩溃原因的任何信息  您正在使用的图书馆非常古老而且被遗弃了。阅读ReadME.MD

因此,该库的开发人员不支持打开问题无用。你应该尝试其他解决方案。您可以使用RecyclerViewGridLayoutmanager尝试This one或类似内容。

答案 1 :(得分:1)

看起来您正在使用此库:https://github.com/TonicArtos/StickyGridHeaders

将其添加到您的依赖项:

dependencies {
   compile "com.tonicartos:stickygridheaders:1.0.1"
}

答案 2 :(得分:1)

尝试使用this,它不是那么老,应该可以正常使用appcompat

首先添加此依赖项

compile 'com.codewaves.stickyheadergrid:stickyheadergrid:0.9.6'
  1. 通过继承StickyHeaderGridAdapter
  2. 实现适配器
  3. 为每个标题和项目类型创建持有者类。使用HeaderViewHolderItemViewHolder作为基类。
  4. 覆盖并实施getSectionCount()getSectionItemCount(int section)onCreateHeaderViewHolder(ViewGroup parent, int headerType)onCreateItemViewHolder(ViewGroup parent, int itemType)onBindHeaderViewHolder(HeaderViewHolder viewHolder, int section)onBindItemViewHolder(ItemViewHolder viewHolder, int section, int offset)
  5. 创建一个包含所需列数的StickyHeaderGridLayoutManager,并将其分配给您的RecyclerView
  6. 仅使用StickyHeaderGridAdapter::notify*种方法
  7. 希望这有帮助。