我目前正在制作应用,但仍然存在内存问题。我们的启动屏幕只有背景和按钮,通常使用160 MB的RAM。这对于它正在做的事情来说太过分了。
这种趋势在我的应用程序中继续存在。
我已经包含了XML和java代码。我还看了一下内存的分配情况。几乎所有的内存都被三件事所占据。三个准确的发送。我不知道这意味着什么。
package com.example.tonymurchison.illuminandus;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private ImageView startButton;
private ImageView fadeView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getSupportActionBar().hide();
startButton = (ImageView) findViewById(R.id.start_button);
}
public void startButtonClick(View v){
//TODO create animation
Intent intent = new Intent(MainActivity.this,LevelSelect.class);
startActivity(intent);
finish();
}
private void animateIn(ImageView image) {
Animation fadein = new AlphaAnimation(0.f, 1.f);
fadein.setDuration(500);
final View viewToAnimate = image;
fadein.setAnimationListener(new Animation.AnimationListener(){
@Override
public void onAnimationStart(Animation animation){}
@Override
public void onAnimationRepeat(Animation animation){}
@Override
public void onAnimationEnd(Animation animation){
Intent intent = new Intent(MainActivity.this,LevelSelect.class);
startActivity(intent);
}
});
image.startAnimation(fadein);
}
}
的xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
tools:context="com.example.tonymurchison.illuminandus.MainActivity"
android:background="@drawable/titlescreen_background">
<ImageView
android:layout_width="300dp"
android:layout_height="wrap_content"
android:id="@+id/start_button"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/start_button"
android:onClick="startButtonClick"/>
</RelativeLayout>