【问题标题】:How to display an ImageView on the whole screen on android?如何在android的整个屏幕上显示ImageView?
【发布时间】:2015-02-15 21:44:53
【问题描述】:

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

【问题讨论】:

  • 请显示您的代码。

标签: java android imageview uri


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-01-23
    • 1970-01-01
    • 2011-11-18
    • 1970-01-01
    • 1970-01-01
    • 2021-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多