Java 跳过66帧!应用程序可能在其主线程上做了太多工作
因此,我在CardView中有一个带有图像按钮和文本视图的活动。出于某种原因,每当我尝试在应用程序中打开活动时,它需要一段时间才能打开,在控制台中,它会给我以下消息:跳过66帧!应用程序可能在其主线程上做了太多工作。当我移除图像按钮时,活动是否正常加载?有人知道为什么吗 `Java 跳过66帧!应用程序可能在其主线程上做了太多工作,java,android,multithreading,Java,Android,Multithreading,因此,我在CardView中有一个带有图像按钮和文本视图的活动。出于某种原因,每当我尝试在应用程序中打开活动时,它需要一段时间才能打开,在控制台中,它会给我以下消息:跳过66帧!应用程序可能在其主线程上做了太多工作。当我移除图像按钮时,活动是否正常加载?有人知道为什么吗 ` `在ImageButtons中,图像可能太大,可能有太多图像或两者的组合。xml属性android:src使用ImageView.setImageResource()在UI线程上执行解码。请注意,ImageButton是
`在
ImageButton
s中,图像可能太大,可能有太多图像或两者的组合。xml属性android:src
使用ImageView.setImageResource()
在UI线程上执行解码。请注意,ImageButton
是一个ImageView
也见。
< P>如果你不使用你的RelayayAUP来让你的孩子们以非线性的方式彼此相对,那么考虑用线性布局代替。RelativeLayout需要两个布局过程来布局其内容此外,如果某些视图未立即显示,您可能希望将其移动到ViewStub中。我通过不使用xml src标记,而是通过编程设置ImageViewer位图来避免此问题。加载图像可能会占用大量资源,通常建议您在UI线程下执行此操作。android有一些关于这个主题的非常集中的教程:你可能在emulator上看到了这个消息吗?虽然人们所说的关于加载图像的一切都是真实的,但是模拟器的速度很慢。如果那是你唯一看到“问题”的地方,那就不是真正的问题。
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="200dp"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="10dp"
>
<TextView
android:id="@+id/info_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Locanda La Sementa"
android:padding="8dp"
android:background="#424242"
android:textColor="@android:color/white"
android:layout_alignParentBottom="true"
android:gravity="bottom"
/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="170dp"
android:src="@drawable/semanta"
android:scaleType="fitXY"
android:id="@+id/semata"
android:background="@null"
/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view2"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="200dp"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="10dp"
android:layout_below="@+id/card_view"
>
<TextView
android:id="@+id/info_text3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="L’Altro Frantoio"
android:padding="8dp"
android:background="#424242"
android:textColor="@android:color/white"
android:layout_alignParentBottom="true"
android:gravity="bottom"
/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="170dp"
android:src="@drawable/fran"
android:scaleType="centerCrop"
android:id="@+id/frantoio"
android:background="@null"
/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view3"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="200dp"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="10dp"
android:layout_below="@+id/card_view2"
>
<TextView
android:id="@+id/info_text2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Domus Hernica"
android:padding="8dp"
android:background="#424242"
android:textColor="@android:color/white"
android:layout_alignParentBottom="true"
android:gravity="bottom"
/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="170dp"
android:src="@drawable/ernica"
android:scaleType="centerCrop"
android:id="@+id/ernica"
android:background="@null"
/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view4"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="200dp"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="10dp"
android:layout_below="@+id/card_view3"
>
<TextView
android:id="@+id/info_text4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Pizzeria la Ciocia"
android:padding="8dp"
android:background="#424242"
android:textColor="@android:color/white"
android:layout_alignParentBottom="true"
android:gravity="bottom"
/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="170dp"
android:src="@drawable/ciocia"
android:scaleType="centerCrop"
android:id="@+id/ciocia"
android:background="@null"
/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view6"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="200dp"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="10dp"
android:layout_below="@+id/card_view4"
>
<TextView
android:id="@+id/info_text6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="L'Aia Antica"
android:padding="8dp"
android:background="#424242"
android:textColor="@android:color/white"
android:layout_alignParentBottom="true"
android:gravity="bottom"
/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="170dp"
android:src="@drawable/laia_antica"
android:scaleType="centerCrop"
android:id="@+id/antica"
android:background="@null"
/>
</android.support.v7.widget.CardView>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:height="80dp"
android:text="More"
android:textSize="17dp"
android:id="@+id/more_Button"
android:layout_below="@+id/card_view6"
android:background="#424242"
android:textColor="@android:color/white"
/>
</RelativeLayout>
</ScrollView>