0
사용자가 선택할 수있는 몇 개의 버튼이 있는데 이미지를 표시하지만 이미지를 서로 쌓아 놓고 이전 이미지를 삭제하지는 않습니다. 나는 비슷한 질문을 여기에서 발견했다. 그러나 그것은 아직도 일하는 것처럼 보이지 않는다.새 이미지를 선택한 후 이미지 삭제
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SlidingDrawer;
public class Samples extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.samples);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
final SlidingDrawer slider = (SlidingDrawer) findViewById(R.id.sD2);
slider.animateOpen();
Button next = (Button) findViewById(R.id.samplea);
Button next1 = (Button) findViewById(R.id.sampleb);
Button next2 = (Button) findViewById(R.id.samplec);
Button next3 = (Button) findViewById(R.id.sampled);
Button next4 = (Button) findViewById(R.id.samplee);
Button next5 = (Button) findViewById(R.id.samplef);
Button next6 = (Button) findViewById(R.id.sampleg);
Button next7 = (Button) findViewById(R.id.sampleh);
Button next8 = (Button) findViewById(R.id.samplei);
Button next9 = (Button) findViewById(R.id.samplej);
Button next10 = (Button) findViewById(R.id.samplek);
Button next11 = (Button) findViewById(R.id.samplel);
Button next12 = (Button) findViewById(R.id.samplem);
Button next13 = (Button) findViewById(R.id.samplen);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// You can turn this into a class variable
final ImageView imageView = (ImageView) findViewById(R.id.iM2);
imageView.setImageResource(R.drawable.samplea);
slider.animateClose();
}
});
next1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
final ImageView imageView = (ImageView) findViewById(R.id.iM2);
imageView.setImageResource(R.drawable.sampleb);
slider.animateClose();
}
});
next2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
final ImageView imageView = (ImageView) findViewById(R.id.iM2);
imageView.setImageResource(R.drawable.samplec);
slider.animateClose();
}
});
next3.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
final ImageView imageView = (ImageView) findViewById(R.id.iM2);
imageView.setImageResource(R.drawable.sampled);
slider.animateClose();
}
});
next4.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
final ImageView imageView = (ImageView) findViewById(R.id.iM2);
imageView.setImageResource(R.drawable.samplee);
slider.animateClose();
}
});
next5.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
final ImageView imageView = (ImageView) findViewById(R.id.iM2);
imageView.setImageResource(R.drawable.samplef);
slider.animateClose();
}
});
next6.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
final ImageView imageView = (ImageView) findViewById(R.id.iM2);
imageView.setImageResource(R.drawable.sampleg);
slider.animateClose();
}
});
next7.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
final ImageView imageView = (ImageView) findViewById(R.id.iM2);
imageView.setImageResource(R.drawable.sampleh);
slider.animateClose();
}
});
next8.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
final ImageView imageView = (ImageView) findViewById(R.id.iM2);
imageView.setImageResource(R.drawable.samplei);
slider.animateClose();
}
});
next9.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
final ImageView imageView = (ImageView) findViewById(R.id.iM2);
imageView.setImageResource(R.drawable.samplej);
slider.animateClose();
}
});
next10.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
final ImageView imageView = (ImageView) findViewById(R.id.iM2);
imageView.setImageResource(R.drawable.samplek);
slider.animateClose();
}
});
next11.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
final ImageView imageView = (ImageView) findViewById(R.id.iM2);
imageView.setImageResource(R.drawable.samplel);
slider.animateClose();
}
});
next12.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
final ImageView imageView = (ImageView) findViewById(R.id.iM2);
imageView.setImageResource(R.drawable.samplem);
slider.animateClose();
}
});
next13.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
final ImageView imageView = (ImageView) findViewById(R.id.iM2);
imageView.setImageResource(R.drawable.samplen);
slider.animateClose();
}
});
}
}
및 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">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/iM2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitStart" />
</RelativeLayout>
</ScrollView>
<SlidingDrawer
android:id="@+id/sD2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:content="@+id/content"
android:handle="@+id/handle" >
<Button
android:id="@+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Sample" />
<RelativeLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/sampleshd">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/samplea"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="@drawable/sampleabutton" />
<Button
android:id="@+id/sampleb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="20dp"
android:layout_below="@+id/samplea"
android:background="@drawable/samplebbutton"
android:longClickable="true"/>
여기 내 전체 코드입니다.
내 xml 코드를 추가했습니다. 그냥이 코드가 작동하는지, 내가 묻는 이유는 내가 삼성 s2 g (ICS)와 삼성 (버전 2 또는 3)이 애플 리케이션을 테스트 할 때 잘 동작한다는 것이다. 하지만 몇 가지 이미지를 선택하거나 다른 것들을 선택하면 내 10.1 인치 타블렛에서 앱에있는 다른 것들은 앱이 작동을 멈추고 타블렛에서 홈 화면으로 돌아갑니다. (태블릿, 안드로이드 버전은 4.0.4입니다.) – Allrounder
좋아, XML에 따르면, 내가 생각한 것이 아니라고 말하는 것입니다. 그러나 이미지를 올바르게 선택한 후에 오류가 발생하면 대부분 메모리 누수가 발생할 가능성이 큽니다. MAT로 확인하십시오. – yahya
안녕하십니까, 늦게 답장하여 죄송합니다. 원래 질문에서 위의 태블릿에서 앱을 테스트 할 때 오류가 발생했습니다. – Allrounder