以下是我的网格构建器类在应用程序启动时在主活动中使用的示例。
public class GridBuilderActivity extends BaseAdapter {
private Context mcontext;
private final String[] featurename;
private final int[] Imageid;
public GridBuilderActivity(Context context, String[] featurename, int[] Imageid) {
mcontext = context;
this.featurename = featurename;
this.Imageid = Imageid;
}
@Override
public int getCount() {
return Imageid.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View grid;
LayoutInflater inflater = (LayoutInflater) mcontext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
grid = new View(mcontext);
grid = inflater.inflate(R.layout.grid_layout, null);
TextView textView = (TextView) grid.findViewById(R.id.gridtextview);
ImageView imageView = (ImageView) grid.findViewById(R.id.gridimage);
textView.setText(featurename[position]);
imageView.setImageResource(Imageid[position]);
//Density wise text size fixing
float density = mcontext.getResources().getDisplayMetrics().density;
if (density >= 4.0) {
//System.out.println("Ex");
textView.setTextSize(15);
}
if (density >= 3.0) {
//System.out.println("hp");
textView.setTextSize(14);
}
if (density >= 2.0) {
//System.out.println("xhp");
textView.setTextSize(13);
}
if (density >= 1.5) {
//System.out.println("hpin");
textView.setTextSize(12);
}
if (density >= 1.0) {
// System.out.println("mp");
textView.setTextSize(11);
}
//Fixing finished here
} else {
grid = (View) convertView;
}
return grid;
}
}
许多手机在应用启动时会出现以下警告,应用程序启动后几秒钟后手机会一直卡住。
W/CursorWindow: Window is full: requested allocation 72 bytes, free space 40 bytes, window size 2097152 bytes
W/CursorWindow: Window is full: requested allocation 72 bytes, free space 40 bytes, window size 2097152 bytes
W/CursorWindow: Window is full: requested allocation 72 bytes, free space 40 bytes, window size 2097152 bytes
请帮忙修复这个问题。这对应用程序的性能产生了严重影响。我从MainActivity中传递所需的参数来调用它。
以下是布局的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/WhiteSmoke"
android:orientation="vertical">
<include
layout="@layout/stdtoolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/WhiteSmoke"
android:scrollbars="none">
<!--<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/WhiteSmoke">-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="10dp"
android:orientation="vertical">
//1st row
//height 330
<GridView
android:id="@+id/grid"
android:layout_width="match_parent"
android:layout_height="420dp"
android:background="@color/White"
android:columnWidth="90dp"
android:gravity="center"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" />
//2nd row
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@color/white"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:text="Entertainment" />
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:drawableTop="@mipmap/dailytemp"
android:padding="10dp"
android:text="Text1" />
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/text1"
android:drawableTop="@mipmap/youtemp"
android:padding="10dp"
android:text="text2" />
</RelativeLayout>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
//3rd row
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@color/White"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="5dp"
android:text="Care And Share "
android:textAlignment="center" />
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<TextView
android:id="@+id/appupdate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/support"
android:layout_gravity="center"
android:drawableTop="@drawable/update"
android:padding="15dp"
android:text="Update"
android:textAlignment="center" />
<TextView
android:id="@+id/usermanual"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/support"
android:layout_gravity="center"
android:layout_toEndOf="@+id/appupdate"
android:drawableTop="@drawable/manual"
android:padding="15dp"
android:text="Manual"
android:textAlignment="center" />
<TextView
android:id="@+id/support"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="2dp"
android:layout_toEndOf="@+id/usermanual"
android:drawableTop="@drawable/help"
android:padding="15dp"
android:text="Support"
android:textAlignment="center" />
<TextView
android:id="@+id/googleplaylike"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/support"
android:layout_gravity="center_horizontal"
android:layout_toEndOf="@+id/support"
android:drawableTop="@drawable/likeus"
android:padding="15dp"
android:text="@string/rate_google_play"
android:textAlignment="center" />
<TextView
android:id="@+id/shareus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/support"
android:layout_gravity="center"
android:layout_toRightOf="@+id/googleplaylike"
android:drawableTop="@drawable/share"
android:padding="15dp"
android:text="Share"
android:textAlignment="center" />
<TextView
android:id="@+id/hireus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/support"
android:layout_gravity="center"
android:layout_toEndOf="@+id/shareus"
android:drawableTop="@drawable/hireus"
android:padding="15dp"
android:text="Hire Us"
android:textAlignment="center" />
</RelativeLayout>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
//3rd row
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@color/White"
android:orientation="horizontal"
android:weightSum="1">
<android.support.design.widget.TextInputLayout
android:layout_width="240dp"
android:layout_height="wrap_content">
<EditText
android:id="@+id/quickfbet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:hint="@string/quick_feedback" />
</android.support.design.widget.TextInputLayout>
<TextView
android:id="@+id/feedbacksubmitbtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:drawableTop="@mipmap/submit"
android:text="Submit"
android:textAlignment="center" />
<!-- <TextView
android:id="@+id/hireus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.5"
android:drawableTop="@mipmap/hire_us"
android:text="Hire Us"
android:textAlignment="center" />-->
</LinearLayout>
//4th row
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@color/White"
android:orientation="horizontal">
<Button
android:id="@+id/ALS"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ALS"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/banner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/picformat" />
<ImageView
android:id="@+id/gif1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/picformat" />
<ImageView
android:id="@+id/click1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/picformat" />
<ImageView
android:id="@+id/image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/picformat" />
<ImageView
android:id="@+id/gif2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/picformat" />
<ImageView
android:id="@+id/click2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/picformat" />
<ImageView
android:id="@+id/image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/picformat" />
<ImageView
android:id="@+id/gif3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/picformat" />
<ImageView
android:id="@+id/click3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/picformat" />
<ImageView
android:id="@+id/image3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/picformat" />
<ImageView
android:id="@+id/gif4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/picformat" />
<ImageView
android:id="@+id/click4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/picformat" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
当手机启动时出现卡顿,需要查看Logcat日志。
E/ANR_LOG: Current msg <1> = { when=-19s830ms what=122 target=android.app.ActivityThread$H obj=BindServiceData{token=android.os.BinderProxy@d2ea533 intent=Intent { cmp=jss.smartapp/.ConnectionBasedTask }} }
E/ANR_LOG: Current msg <2> = { when=-19s830ms what=116 target=android.app.ActivityThread$H obj=android.os.BinderProxy@d2ea533 }
E/ANR_LOG: Current msg <3> = { when=-19s824ms what=7 target=com.google.android.gms.common.internal.zzh arg2=-1 obj=com.google.android.gms.common.internal.zzo@4aedbd9 }
E/ANR_LOG: Current msg <4> = { when=-19s231ms what=0 target=android.view.ViewRootImpl$ViewRootHandler callback=android.view.View$ScrollabilityCache }
E/ANR_LOG: Current msg <5> = { when=-19s231ms what=0 target=android.view.ViewRootImpl$ViewRootHandler callback=android.view.View$ScrollabilityCache }
E/ANR_LOG: Current msg <6> = { when=-15s804ms what=0 target=android.os.Handler callback=com.google.android.gms.internal.zzces }
E/ANR_LOG: Current msg <7> = { when=+59m38s136ms what=0 target=android.os.Handler callback=com.google.android.gms.internal.zzces }
你能基于这个帮忙做些什么吗?