[英]Android - Show image from resource drawable
I'm new at Android apps and I'm working on a project started by a friend of mine. 我是Android应用程序的新手,正在从事由我的一个朋友发起的项目。 The code below is from a class that loads a view that has a small image with some text around it.
下面的代码来自于一个加载视图的类,该视图的图像较小,周围带有一些文本。
I want the image to appear fullscreen (on the standard Android image viewer) when I click on the thumbnail. 当我单击缩略图时,我希望图像以全屏显示(在标准的Android图像查看器上)。 I tried several different solutions, and none of them worked.
我尝试了几种不同的解决方案,但没有一个起作用。
This example throws the following exception: 本示例引发以下异常:
E/AndroidRuntime(13768): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=android.resource://com.app.mid/2130837533 typ=image/png }
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_n1);
ImageView img = (ImageView) findViewById(imageResource);
img.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("android.resource://com.app.mid/" + R.drawable.p_page_11_image_0001), "image/png");
startActivity(intent);
}
});
}
The images are inside the drawable folder (..\\res\\drawable-xhdpi). 图像位于可绘制文件夹(.. \\ res \\ drawable-xhdpi)中。 I'm using Eclipse ADT and I configured it to run on my Galaxy Nexus.
我正在使用Eclipse ADT,并将其配置为在我的Galaxy Nexus上运行。
Again, I tried several solutions with no luck. 再次,我尝试了几种没有运气的解决方案。 Any thoughts?
有什么想法吗? Thanks
谢谢
Try to use Intent.ACTION_VIEW instead of android.content.Intent.ACTION_VIEW 尝试使用Intent.ACTION_VIEW而不是android.content.Intent.ACTION_VIEW
Intent i = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(yourUri, "image/png");
startActivity(intent);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.