带有参数和按钮的简单Android幻灯片

带有参数和按钮的简单Android幻灯片,android,slideshow,out-of-memory,Android,Slideshow,Out Of Memory,我是android的新手:) 我想用一个数字参数(x)和一个按钮创建一个简单的幻灯片。我有21个图像,点击按钮,我想捕捉x并“滑动”列表中的前x个图像。在一个图像和下一个图像之间,我想等待1秒 最后,我想知道手术过程中经过了多少时间。(对不起我的英语) 在活动和布局的代码下方粘贴: package com.superpibenchmarknative; import android.app.Activity; import android.os.Bundle; import android.o

我是android的新手:)

我想用一个数字参数(x)和一个按钮创建一个简单的幻灯片。我有21个图像,点击按钮,我想捕捉x并“滑动”列表中的前x个图像。在一个图像和下一个图像之间,我想等待1秒

最后,我想知道手术过程中经过了多少时间。(对不起我的英语)

在活动和布局的代码下方粘贴:

package com.superpibenchmarknative;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;



public class ImageActivity extends Activity implements OnClickListener {
private Button start;
private EditText iteractions;
private TextView time;
private ImageView display;
private long after,before;
private int images[] = {R.drawable.image1,R.drawable.image2,R.drawable.image3,
                        R.drawable.image4,R.drawable.image5,R.drawable.image6,R.drawable.image7,
                        R.drawable.image8,R.drawable.image9,R.drawable.image10,R.drawable.image11,
                        R.drawable.image12,R.drawable.image13,R.drawable.image14,R.drawable.image15,
                        R.drawable.image16,R.drawable.image17,R.drawable.image18,R.drawable.image19,
                        R.drawable.image20,R.drawable.image21,
        };
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image);
    setUpUI();
}

private void setUpUI() {
    // TODO Auto-generated method stub
    start = (Button) findViewById(R.id.bntStartCalcolation);
    iteractions = (EditText) findViewById(R.id.etIterations);
    time = (TextView) findViewById(R.id.tvTime);

    start.setOnClickListener(this);
}

@Override
public void onClick(View arg0) {
    //Creo le imageview in base al # di iteractions 
    before = System.currentTimeMillis();
    for (int j = 0; j < Integer.parseInt(iteractions.getText().toString());j++){
        display = (ImageView) findViewById(R.id.ivDisplay);
        display.setImageResource(images[j]);
        Handler handler = new Handler(); 
        handler.postDelayed(new Runnable() { 
             public void run() { 
                  display = null;
                  System.gc();
             } 
        }, 1000); 

    }
    display = null;
    System.gc();
    after = System.currentTimeMillis();
    time.setText(String.valueOf(after-before-1000* Integer.parseInt(iteractions.getText().toString())));
}

}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".ImageActivity" >

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="5dp"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:layout_marginTop="10dp"
    android:padding="5dp"
    android:text="Benchmark del rendering di immagini" />

<EditText
    android:id="@+id/etIterations"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginBottom="5dp"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:layout_marginTop="5dp"
    android:hint="# di iterazioni"
    android:inputType="number"
    android:padding="5dp" />

<Button
    android:id="@+id/bntStartCalcolation"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="5dp"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="5dp"
    android:text="Start Calcolation" />

<ImageView  android:id="@+id/ivDisplay"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_gravity="center"/>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="100" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        android:layout_weight="50"
        android:text="Risultato ottenuto in: " />

    <TextView
        android:id="@+id/tvTime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        android:layout_weight="50" />
</LinearLayout>
package com.superpibenchmarkinate;
导入android.app.Activity;
导入android.os.Bundle;
导入android.os.Handler;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.ImageView;
导入android.widget.TextView;
公共类ImageActivity扩展活动实现OnClickListener{
私人按钮启动;
私人编辑;
私有文本查看时间;
私有图像视图显示;
私人很久以前;
私有int-images[]={R.drawable.image1,R.drawable.image2,R.drawable.image3,
R.drawable.image4,R.drawable.image5,R.drawable.image6,R.drawable.image7,
R.drawable.image8,R.drawable.image9,R.drawable.image10,R.drawable.image11,
R.drawable.image12,R.drawable.image13,R.drawable.image14,R.drawable.image15,
R.drawable.image16,R.drawable.image17,R.drawable.image18,R.drawable.image19,
R.drawable.image20,R.drawable.image21,
};
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u图像);
setUpUI();
}
私有void setUpUI(){
//TODO自动生成的方法存根
开始=(按钮)findViewById(R.id.bntStartCalcolation);
iteractions=(EditText)findViewById(R.id.etitorations);
时间=(TextView)findViewById(R.id.tvTime);
start.setOnClickListener(this);
}
@凌驾
公共void onClick(视图arg0){
//基本图像中的Creo le imageview
before=System.currentTimeMillis();
对于(int j=0;j
这是布局图:

package com.superpibenchmarknative;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;



public class ImageActivity extends Activity implements OnClickListener {
private Button start;
private EditText iteractions;
private TextView time;
private ImageView display;
private long after,before;
private int images[] = {R.drawable.image1,R.drawable.image2,R.drawable.image3,
                        R.drawable.image4,R.drawable.image5,R.drawable.image6,R.drawable.image7,
                        R.drawable.image8,R.drawable.image9,R.drawable.image10,R.drawable.image11,
                        R.drawable.image12,R.drawable.image13,R.drawable.image14,R.drawable.image15,
                        R.drawable.image16,R.drawable.image17,R.drawable.image18,R.drawable.image19,
                        R.drawable.image20,R.drawable.image21,
        };
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image);
    setUpUI();
}

private void setUpUI() {
    // TODO Auto-generated method stub
    start = (Button) findViewById(R.id.bntStartCalcolation);
    iteractions = (EditText) findViewById(R.id.etIterations);
    time = (TextView) findViewById(R.id.tvTime);

    start.setOnClickListener(this);
}

@Override
public void onClick(View arg0) {
    //Creo le imageview in base al # di iteractions 
    before = System.currentTimeMillis();
    for (int j = 0; j < Integer.parseInt(iteractions.getText().toString());j++){
        display = (ImageView) findViewById(R.id.ivDisplay);
        display.setImageResource(images[j]);
        Handler handler = new Handler(); 
        handler.postDelayed(new Runnable() { 
             public void run() { 
                  display = null;
                  System.gc();
             } 
        }, 1000); 

    }
    display = null;
    System.gc();
    after = System.currentTimeMillis();
    time.setText(String.valueOf(after-before-1000* Integer.parseInt(iteractions.getText().toString())));
}

}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".ImageActivity" >

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="5dp"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:layout_marginTop="10dp"
    android:padding="5dp"
    android:text="Benchmark del rendering di immagini" />

<EditText
    android:id="@+id/etIterations"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginBottom="5dp"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:layout_marginTop="5dp"
    android:hint="# di iterazioni"
    android:inputType="number"
    android:padding="5dp" />

<Button
    android:id="@+id/bntStartCalcolation"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="5dp"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="5dp"
    android:text="Start Calcolation" />

<ImageView  android:id="@+id/ivDisplay"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_gravity="center"/>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="100" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        android:layout_weight="50"
        android:text="Risultato ottenuto in: " />

    <TextView
        android:id="@+id/tvTime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        android:layout_weight="50" />
</LinearLayout>

这段代码不起作用,它创建了一个异常

OutOfMemoryError:位图大小超出vm预算

谁能帮我解决这个问题??)无论如何,谢谢你

一切都很好:D但我还有一点问题

我不明白为什么时间总是消极的!!! 你们谁知道为什么??[postDelayed不起作用?!?:(]

解决方法:安卓系统、操作系统、系统时钟、睡眠(1000);


另一个错误,图像视图在设置图像后没有更改,任何建议???

将大堆添加到清单文件中的应用程序中

<application ... android:largeHeap="true" >

查找Android屏幕分辨率。

开发者网站上有一个关于加载大型位图文件的小指南。其想法是加载分辨率较低的文件,以便将其放入内存中: