我是新人,所以如果我问一个愚蠢的问题,请不要这么难。 我试图使用drawableIanimations运行应用程序,但不是按钮或弹出动画,我的意思是,从2到4秒的视频逐帧动画。我从2到4秒的视频中提取,每秒10到30帧。有些动画将android:oneshot设置为false,有些设置为true。 所以,我正在尝试开发一个应用程序,其上有一个RelativeLayout和一个ImageView,然后是一个带有10个按钮的LinearLayout来启动每个动画。 我的应用程序一开始运行良好,但有时会停止,我得到内存不足错误。 我不知道我选择的结构是对的还是我做错了什么。 在这里,我向您提供一些有关我正在做的事情的信息,为您提供帮助或提供一个好的建议或让我在这个应用程序的正确轨道上。
图片 10个动画,每个4秒。每秒30张图片。 1200张图片。 如果我为每个屏幕尺寸制作图像,我知道我会杀死内存,所以我只使用drawable-ldpi目录中的图像。我不知道是否可以。
screenOrientation =“肖像”。
每张图片尺寸:135x240 21.8kb
activity_main.xml中
<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="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:screenOrientation="portrait"
tools:context="com.absolutkarlos.roccoalejandro.MainActivity" >
<ImageView
android:id="@+id/imagen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:contentDescription="@string/imageninicial" />
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imagen"
android:layout_marginBottom="5dp" >
<LinearLayout
android:id="@+id/botonera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal" >
<Button
android:id="@+id/startanimation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="@string/iniciar" />
<Button
android:id="@+id/stopanimation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="@string/stop" />
<Button
android:id="@+id/entrada01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button3" />
<Button
android:id="@+id/entrada02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button4" />
<Button
android:id="@+id/entrada03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button5" />
<Button
android:id="@+id/entrada04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button6" />
<Button
android:id="@+id/entrada05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button7" />
<Button
android:id="@+id/entrada06"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button8" />
<Button
android:id="@+id/entrada07"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button9" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button10" />
</LinearLayout>
MainActivity.java
package com.absolutkarlos.roccoalejandro;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.graphics.drawable.AnimationDrawable;
import android.widget.ImageView;
import android.view.View;
import android.widget.Button;
import android.view.View.OnClickListener;
public class MainActivity extends ActionBarActivity {
Button button;
private AnimationDrawable frameAnimation;
private ImageView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
// Type casting the Image View
view = (ImageView) findViewById(R.id.imagen);
// Setting animation_list.xml as the background of the image view
view.setBackgroundResource(R.drawable.entrada01);
// Type casting the Animation drawable
frameAnimation = (AnimationDrawable) view.getBackground();
}
public void addListenerOnButton() {
view = (ImageView) findViewById(R.id.imagen);
button = (Button) findViewById(R.id.startanimation);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
frameAnimation.stop();
view.setBackgroundResource(R.drawable.caricias_durmiendose);
frameAnimation = (AnimationDrawable) view.getBackground();
frameAnimation.start();
}
});
button = (Button) findViewById(R.id.stopanimation);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
frameAnimation.stop();
view.setBackgroundResource(R.drawable.caricias_volteado);
frameAnimation = (AnimationDrawable) view.getBackground();
frameAnimation.start();
}
});
button = (Button) findViewById(R.id.entrada01);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
frameAnimation.stop();
view.setBackgroundResource(R.drawable.entrada01);
frameAnimation = (AnimationDrawable) view.getBackground();
frameAnimation.start();
}
});
button = (Button) findViewById(R.id.entrada02);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
frameAnimation.stop();
view.setBackgroundResource(R.drawable.entrada02);
frameAnimation = (AnimationDrawable) view.getBackground();
frameAnimation.start();
}
});
button = (Button) findViewById(R.id.entrada03);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
frameAnimation.stop();
view.setBackgroundResource(R.drawable.entrada03);
frameAnimation = (AnimationDrawable) view.getBackground();
frameAnimation.start();
}
});
button = (Button) findViewById(R.id.entrada04);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
frameAnimation.stop();
view.setBackgroundResource(R.drawable.entrada04);
frameAnimation = (AnimationDrawable) view.getBackground();
frameAnimation.start();
}
});
button = (Button) findViewById(R.id.entrada05);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
frameAnimation.stop();
view.setBackgroundResource(R.drawable.entrada05);
frameAnimation = (AnimationDrawable) view.getBackground();
frameAnimation.start();
}
});
button = (Button) findViewById(R.id.entrada06);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
frameAnimation.stop();
view.setBackgroundResource(R.drawable.entrada06);
frameAnimation = (AnimationDrawable) view.getBackground();
frameAnimation.start();
}
});
button = (Button) findViewById(R.id.entrada07);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
frameAnimation.stop();
view.setBackgroundResource(R.drawable.entrada07);
frameAnimation = (AnimationDrawable) view.getBackground();
frameAnimation.start();
}
});
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
// Start animation when in Focus
frameAnimation.start();
} else {
// stop animation when not in Focus
frameAnimation.stop();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
每个动画列表* .xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true">
<item android:drawable="@drawable/entrada006" android:duration="30" />
<item android:drawable="@drawable/entrada007" android:duration="30" />
<item android:drawable="@drawable/entrada008" android:duration="30" />
<item android:drawable="@drawable/entrada009" android:duration="30" />
<item android:drawable="@drawable/entrada010" android:duration="30" />
<item android:drawable="@drawable/entrada011" android:duration="30" />
<item android:drawable="@drawable/entrada012" android:duration="30" />
<item android:drawable="@drawable/entrada013" android:duration="30" />
<item android:drawable="@drawable/entrada014" android:duration="30" />
<item android:drawable="@drawable/entrada015" android:duration="30" />
<item android:drawable="@drawable/entrada016" android:duration="30" />
<item android:drawable="@drawable/entrada017" android:duration="30" />
<item android:drawable="@drawable/entrada018" android:duration="30" />
<item android:drawable="@drawable/entrada019" android:duration="30" />
<item android:drawable="@drawable/entrada020" android:duration="30" />
</animation-list>
我希望有人可以帮助我,或者只是给我一个建议继续...... 提前致谢。此致