ImageView中显示的图像小于源图像

时间:2016-02-18 02:54:52

标签: java android

我正在使用AsyncTask从互联网上下载图像并将其显示在ImageView中。对于我的应用,使用API​​调用检索图像URL,并使用它在ImageView中显示。它有效,但图像非常小,很难看到。我不知道这是因为图片没有存储在drawable中,或者我是否遗漏了代码中的某些内容。为什么要调整我的图像大小?

我的应用中的图片尺寸

enter image description here

图像的实际尺寸

enter image description here

RecipePage.java

Results result = new Results();

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_recipeviewer, container, false);

        new DownloadImageTask((ImageView) rootView.findViewById(R.id.recipe_image))
                .execute(result.getURL()); //getURL() just contains the URL of the image
        return rootView;


    }

    class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
        ImageView bmImage;

        public DownloadImageTask(ImageView bmImage) {
            this.bmImage = bmImage;
        }

        protected Bitmap doInBackground(String... urls) {
            String urldisplay = urls[0];
            Bitmap mIcon11 = null;
            try {
                InputStream in = new java.net.URL(urldisplay).openStream();
                mIcon11 = BitmapFactory.decodeStream(in);
            } catch (Exception e) {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }
            return mIcon11;
        }

        protected void onPostExecute(Bitmap result) {
            bmImage.setImageBitmap(result);
        }
    }

fragment_recipeviewer.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/recipe_image" />
</LinearLayout>

我可能会遗漏一些显而易见的事情或做一些愚蠢的事情。有什么解决方案吗?

2 个答案:

答案 0 :(得分:0)

更新您的布局文件。

scaletypes有多种选择。选择最适合你的东西。

LIMIT

答案 1 :(得分:0)

原因是:
Nexus 5(您使用的仿真器)的分辨率为: 1080 x 1920 像素
并且(your image)的分辨率为: 350×233 像素
因此,您的图像看起来很小但显示正确

如果您想增加图像尺寸,可以

<ImageView
    android:id="@id/img"
    android:layout_width="150dp" // modify your width 
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:scaleType="fitCenter" />

但请记住,如果在较大的视图上显示小图像,则图像质量会很差 希望这个帮助

相关问题