나는 아주 간단한 예제를 이해합니다 - 안드로이드에있는 SD 카드의 imageview에 단일 이미지를 표시하십시오. 나는 USB를 통해 실제 장치에서 C# 및 디버그 응용 프로그램과 함께 Xamarin을 사용하고 있습니다.왜 화면을 돌릴 때 이미지가 사라 집니까?
구성 요소 "ImageView"는 이미지를 올바르게 표시하지만 화면을 회전하면 이미지가 표시되지 않습니다.
Activity1.cs
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using System.IO;
using Android.Graphics;
namespace DisplayImageFromSDCard
{
[Activity(Label = "DisplayImageFromSDCard", MainLauncher = true, Icon = "@drawable/icon")]
public class Activity1 : Activity
{
ImageView imageView;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
imageView = FindViewById<ImageView>(Resource.Id.imageView1);
Button button = FindViewById<Button>(Resource.Id.MyButton);
button.Click += button_Click;
}
void button_Click(object sender, EventArgs e)
{
var sdCardPath = Android.OS.Environment.ExternalStorageDirectory.Path;
var imageFilePath = System.IO.Path.Combine(sdCardPath, "SampleImageFile.jpg");
if (System.IO.File.Exists(imageFilePath))
{
var imageFile = new Java.IO.File(imageFilePath);
Bitmap bitmap = BitmapFactory.DecodeFile(imageFile.AbsolutePath);
imageView.SetImageBitmap(bitmap);
}
else
{
//Display No Image Found
}
}
}
}
Main.axml 어떤 도움
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/MyButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/MyButtonText" />
<ImageView
android:src="@android:drawable/ic_menu_gallery"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imageView1" />
</LinearLayout>
감사. 화면이 꺼져 turnd하고 다시, - - 화면이보기가 기본
<ImageView
android:src="@android:drawable/ic_menu_gallery"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imageView1" />
당신이 거기에 어떤 이미지를 가지고 있겠지로 만들어집니다 그래서 때
회전 :
에 대한 내 대답에 모습을 가질 수 없습니다 당신은 메모리에 이미지를 유지해야하며, 사용자 정의 조각과 트릭을 할 수 있습니다 "당신이 현재의 상태를 저장해야 뷰가 다시 생성 될 때 모든 것이 다시 돌아올 것"에 대해 설명하십시오. 죄송합니다. 영어는 많이 모릅니다. –
나는 내 대답을 편집했다. – laymelek