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

标签 java android imageview uri

在我的应用程序中,我需要从图库中拍摄一张照片(我有相应的工作代码,它为我提供了照片的 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/

相关文章:

java - 为什么SimpleJdbcCall会忽略@Transactional注解

java - 如何创建具有多态委托(delegate)的动态代理?

Android ImageView 布局重力不起作用

java - 将投影添加到吗啡查询

android - 如何仅从 Google Photos 应用程序中选择图像? Android 谷歌相册 Intent

android - VectorDrawable 在 Android 上显示不正确

java - APK 未从下载文件夹中删除

android - 如何设置 imageview 适合屏幕?

android 图像在屏幕上看起来太小,如何缩放以适合屏幕? wrap_content 似乎不起作用

java - Java 处理输入时出现问题