应用程序在实现滚动卡视图时崩溃

时间:2018-01-08 07:02:58

标签: android performance android-layout android-cardview android-scrollview

以下是我的代码。代码格式为

 <ScrollView>
    <LinearLayout>
         <CardView>  <LinearLayout> <TextView> <ImageView> </LinearLayout> </CardView>
         .  //5 more card views similar to this of same Content.
         .
    </LinearLayout>
</ScrollView>

应用程序在手机上运行时崩溃。 logcat读取

01-08 12:12:46.869 24638-24740/com.example.android.cardapplication 
I/OpenGLRenderer: Initialized EGL, version 1.4
01-08 12:12:49.082 24638-24740/com.example.android.cardapplication I/Adreno: BLTLIB: Semaphore error, disabling MT
01-08 12:12:51.089 24638-24740/com.example.android.cardapplication I/Adreno: BLTLIB: Semaphore error count 1
01-08 12:13:03.269 24638-24638/com.example.android.cardapplication I/Choreographer: Skipped 346 frames!  The application may be doing too much work on its main thread.
01-08 12:13:08.353 24638-24643/com.example.android.cardapplication I/art: Thread[2,tid=24643,WaitingInMainSignalCatcherLoop,Thread*=0x55c739e330,peer=0x12d5a0a0,"Signal Catcher"]: reacting to signal 3
01-08 12:13:08.419 24638-24643/com.example.android.cardapplication I/art: Wrote stack traces to '/data/anr/traces.txt'
01-08 12:13:11.863 24638-24638/com.example.android.cardapplication I/Choreographer: Skipped 515 frames!  The application may be doing too much work on its main thread.
01-08 12:13:14.860 24638-24638/com.example.android.cardapplication I/Choreographer: Skipped 179 frames!  The application may be doing too much work on its main thread.
01-08 12:13:24.432 24638-24638/com.example.android.cardapplication I/Choreographer: Skipped 214 frames!  The application may be doing too much work on its main thread.
01-08 12:13:28.753 24638-24638/com.example.android.cardapplication I/Choreographer: Skipped 258 frames!  The application may be doing too much work on its main thread.

我还添加了CardView依赖项, 尝试使用嵌套的Scroll视图和 使用了Layout_height =&#34; wrap_content&#34;在cardView但无济于事。 我还没有在MainActivity.Java中添加任何内容。

请指明我的错误以及我必须遵循的其他方式。

我的完整代码如下: -

  
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

 <LinearLayout
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical">

    <android.support.v7.widget.CardView
    android:id="@+id/cardview1"
    android:layout_width="match_parent"
    android:layout_height="182dp"
    android:layout_margin="5dp"
    android:background="@color/colorPrimaryDark"
    app:cardCornerRadius="10dp">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="160dp"
            android:src="@drawable/filter" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="22dp"
            android:layout_gravity="center_vertical"
            android:background="@color/colorPrimaryDark"
            android:gravity="center_horizontal"
            android:text="FILTER COFFEE"
            android:textColor="#ffff00" />

      </LinearLayout>

     </android.support.v7.widget.CardView>
     <android.support.v7.widget.CardView
     android:id="@+id/cardview5"
     android:layout_width="match_parent"
     android:layout_height="182dp"
     android:layout_margin="5dp"
     android:background="@color/colorPrimaryDark"
     app:cardCornerRadius="10dp">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="160dp"
            android:src="@drawable/filter" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="22dp"
            android:layout_gravity="center_vertical"
            android:background="@color/colorPrimaryDark"
            android:gravity="center_horizontal"
            android:text="FILTER COFFEE"
             android:textColor="#ffff00" />

     </LinearLayout>

   </android.support.v7.widget.CardView>
  <android.support.v7.widget.CardView
    android:id="@+id/cardview6"
    android:layout_width="match_parent"
    android:layout_height="182dp"
    android:layout_margin="5dp"
    android:background="@color/colorPrimaryDark"
    app:cardCornerRadius="10dp">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="160dp"
            android:src="@drawable/filter" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="22dp"
            android:layout_gravity="center_vertical"
            android:background="@color/colorPrimaryDark"
            android:gravity="center_horizontal"
            android:text="FILTER COFFEE"
            android:textColor="#ffff00" />

    </LinearLayout>

   </android.support.v7.widget.CardView>
   <android.support.v7.widget.CardView
    android:id="@+id/cardview2"
    android:layout_width="match_parent"
    android:layout_height="182dp"
    android:layout_margin="5dp"
    android:background="@color/colorPrimaryDark"
    app:cardCornerRadius="10dp">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="160dp"
            android:src="@drawable/filter" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="22dp"
            android:layout_gravity="center_vertical"
            android:background="@color/colorPrimaryDark"
            android:gravity="center_horizontal"
            android:text="FILTER COFFEE"
            android:textColor="#ffff00" />

    </LinearLayout>

   </android.support.v7.widget.CardView>
   <android.support.v7.widget.CardView
    android:id="@+id/cardview3"
    android:layout_width="match_parent"
    android:layout_height="182dp"
    android:layout_margin="5dp"
    android:background="@color/colorPrimaryDark"
    app:cardCornerRadius="10dp">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="160dp"
            android:src="@drawable/filter" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="22dp"
            android:layout_gravity="center_vertical"
            android:background="@color/colorPrimaryDark"
            android:gravity="center_horizontal"
            android:text="FILTER COFFEE"
            android:textColor="#ffff00" />

    </LinearLayout>

   </android.support.v7.widget.CardView>
   <android.support.v7.widget.CardView
    android:id="@+id/cardview4"
    android:layout_width="match_parent"
    android:layout_height="182dp"
    android:layout_margin="5dp"
    android:background="@color/colorPrimaryDark"
    app:cardCornerRadius="10dp">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="160dp"
            android:src="@drawable/filter" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="22dp"
            android:layout_gravity="center_vertical"
            android:background="@color/colorPrimaryDark"
            android:gravity="center_horizontal"
            android:text="FILTER COFFEE"
            android:textColor="#ffff00" />

       </LinearLayout>

     </android.support.v7.widget.CardView>


 </LinearLayout>

</ScrollView>

我该怎么做才能解决我的错误?

0 个答案:

没有答案