gpt4 book ai didi

java - 如何在android上全屏显示ImageView?

转载 作者:行者123 更新时间:2023-12-01 11:54:45 27 4
gpt4 key购买 nike

在我的应用程序中,我需要从图库中拍摄一张照片(我有相应的工作代码,它为我提供了照片的 Uri)并将该 Uri 放入 ImageView 中。我遇到的问题是,即使我在布局中将 ImageVIew 的高度和宽度设置为 match_parent,图片也没有像我想要的那样覆盖整个屏幕。有什么方法可以将图库中的每张图片设置为在整个屏幕上显示吗?

这是我的代码:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
System.out.println("Image Path : " + selectedImagePath);
img.setImageURI(selectedImageUri);
}
}
}

public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}

public void onClick(View v) {
// TODO Auto-generated method stub
if(v.getId()==btn.getId())
{
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE);
}
}

这是我的布局:

<RelativeLayout 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="horizontal" >

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="30"
android:orientation="vertical" >

<Button
android:id="@+id/gallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />


<ImageView
android:id="@+id/pic"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>

</RelativeLayout>

最佳答案

您可以使用以下android:scaleType="fitXY"

关于java - 如何在android上全屏显示ImageView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28531538/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com