• <bdo id='anmrv'></bdo><ul id='anmrv'></ul>

    <i id='anmrv'><tr id='anmrv'><dt id='anmrv'><q id='anmrv'><span id='anmrv'><b id='anmrv'><form id='anmrv'><ins id='anmrv'></ins><ul id='anmrv'></ul><sub id='anmrv'></sub></form><legend id='anmrv'></legend><bdo id='anmrv'><pre id='anmrv'><center id='anmrv'></center></pre></bdo></b><th id='anmrv'></th></span></q></dt></tr></i><div id='anmrv'><tfoot id='anmrv'></tfoot><dl id='anmrv'><fieldset id='anmrv'></fieldset></dl></div>

      <tfoot id='anmrv'></tfoot>

      <legend id='anmrv'><style id='anmrv'><dir id='anmrv'><q id='anmrv'></q></dir></style></legend>

    1. <small id='anmrv'></small><noframes id='anmrv'>

      Android Image Dialog/Popup 与图像大小相同且无边框

      时间:2023-08-30

    2. <i id='rb8Cq'><tr id='rb8Cq'><dt id='rb8Cq'><q id='rb8Cq'><span id='rb8Cq'><b id='rb8Cq'><form id='rb8Cq'><ins id='rb8Cq'></ins><ul id='rb8Cq'></ul><sub id='rb8Cq'></sub></form><legend id='rb8Cq'></legend><bdo id='rb8Cq'><pre id='rb8Cq'><center id='rb8Cq'></center></pre></bdo></b><th id='rb8Cq'></th></span></q></dt></tr></i><div id='rb8Cq'><tfoot id='rb8Cq'></tfoot><dl id='rb8Cq'><fieldset id='rb8Cq'></fieldset></dl></div>
    3. <legend id='rb8Cq'><style id='rb8Cq'><dir id='rb8Cq'><q id='rb8Cq'></q></dir></style></legend>

          <bdo id='rb8Cq'></bdo><ul id='rb8Cq'></ul>

            <small id='rb8Cq'></small><noframes id='rb8Cq'>

              <tfoot id='rb8Cq'></tfoot>
                <tbody id='rb8Cq'></tbody>

                本文介绍了Android Image Dialog/Popup 与图像大小相同且无边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                目前我正在使用文件浏览器.一切正常,但有一个例外:如果用户单击图像(jpg,png,bmp,..),我希望图像显示在与图像大小相同的对话框或弹出窗口中 - 这样就没有边框了.图像文件位于 sdcard 上.

                At the moment I am working on a file browser. Everything works fine with one exception: If the user clicks on an image (jpg, png, bmp, ..), I want the image to be displayed in a dialog or in a popup which has the same size as the image - so that there are no borders at all. The image files are located on the sdcard.

                这是我目前所拥有的:

                BitmapDrawable bitmap = new BitmapDrawable(context.getResources(), TARGET_PATH);
                
                AlertDialog.Builder imageDialog = new AlertDialog.Builder(context);
                LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                
                View layout = inflater.inflate(R.layout.thumbnail, null);
                ImageView image = (ImageView) layout.findViewById(R.id.thumbnail_IMAGEVIEW);
                image.setImageDrawable(bitmap);
                imageDialog.setView(layout);
                imageDialog.create();
                imageDialog.show();
                

                XML 文件:

                <?xml version="1.0" encoding="utf-8"?>
                <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                
                    <ImageView
                        android:id="@+id/thumbnail_IMAGEVIEW"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentTop="true"
                        android:contentDescription="@string/icon_DESCRIPTION" />
                
                </RelativeLayout>
                

                这是输出:

                图像边缘有丑陋的边框 - 我不希望它们显示出来.我尝试了很多在 google 等中列出的东西和示例. - 还没有任何效果.

                There are ugly borders at the edges of the images - I don't want them to be shown. I tried lots of stuff and examples listed in google, etc.. - nothing worked yet.

                最好的选择是使图像后面的对话框/视图与图像大小相同.另一种方法是将图像背后的背景设置为透明.

                The best option will be to make the dialog/the view behind the image, the same size as the image. Another way could be to set the background behind the image transparent.

                如何实现任何解决方案?我想让背景与图像的大小相同,因此不会留下不可见"的东西,但我也可以使用透明选项.

                How do I achieve any solution? I'd love to make the background the same size as the image is, so there is no "invisible" stuff left, but I will also be okay with the transparent option.

                解决方案:

                // Get screen size
                Display display = context.getWindowManager().getDefaultDisplay();
                Point size = new Point();
                display.getSize(size);
                int screenWidth = size.x;
                int screenHeight = size.y;
                
                // Get target image size
                Bitmap bitmap = BitmapFactory.decodeFile(TARGET);
                int bitmapHeight = bitmap.getHeight();
                int bitmapWidth = bitmap.getWidth();
                
                // Scale the image down to fit perfectly into the screen
                // The value (250 in this case) must be adjusted for phone/tables displays
                while(bitmapHeight > (screenHeight - 250) || bitmapWidth > (screenWidth - 250)) {
                    bitmapHeight = bitmapHeight / 2;
                    bitmapWidth = bitmapWidth / 2;
                }
                
                // Create resized bitmap image
                BitmapDrawable resizedBitmap = new BitmapDrawable(context.getResources(), Bitmap.createScaledBitmap(bitmap, bitmapWidth, bitmapHeight, false));
                
                // Create dialog
                Dialog dialog = new Dialog(context);
                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                dialog.setContentView(R.layout.thumbnail);
                
                ImageView image = (ImageView) dialog.findViewById(R.id.imageview);
                
                // !!! Do here setBackground() instead of setImageDrawable() !!! //
                image.setBackground(resizedBitmap);
                
                // Without this line there is a very small border around the image (1px)
                // In my opinion it looks much better without it, so the choice is up to you.
                dialog.getWindow().setBackgroundDrawable(null);
                
                // Show the dialog
                dialog.show();
                

                XML 文件:

                <?xml version="1.0" encoding="utf-8"?>
                <ImageView xmlns:android="http://schemas.android.com/apk/res/android"
                    android:id="@+id/imageview"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                
                </ImageView>
                

                最终输出:

                推荐答案

                从这里改变你的 ImageView:

                Change your ImageView from this:

                <ImageView
                        android:id="@+id/thumbnail_IMAGEVIEW"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentTop="true"
                        android:contentDescription="@string/icon_DESCRIPTION" />
                

                到这里:

                <ImageView
                        android:id="@+id/thumbnail_IMAGEVIEW"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentTop="true"
                        android:adjustViewBounds="true" <!-- Here is the thing -->
                        android:contentDescription="@string/icon_DESCRIPTION" />
                

                希望这会有所帮助.

                这篇关于Android Image Dialog/Popup 与图像大小相同且无边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:带有数字选择器的 Android PreferenceActivity 对话框 下一篇:使用 ImageView 显示 AlertDialog 而无需任何填充

                相关文章

                最新文章

                <tfoot id='mw4oG'></tfoot>
              1. <legend id='mw4oG'><style id='mw4oG'><dir id='mw4oG'><q id='mw4oG'></q></dir></style></legend>
                  <bdo id='mw4oG'></bdo><ul id='mw4oG'></ul>

                1. <i id='mw4oG'><tr id='mw4oG'><dt id='mw4oG'><q id='mw4oG'><span id='mw4oG'><b id='mw4oG'><form id='mw4oG'><ins id='mw4oG'></ins><ul id='mw4oG'></ul><sub id='mw4oG'></sub></form><legend id='mw4oG'></legend><bdo id='mw4oG'><pre id='mw4oG'><center id='mw4oG'></center></pre></bdo></b><th id='mw4oG'></th></span></q></dt></tr></i><div id='mw4oG'><tfoot id='mw4oG'></tfoot><dl id='mw4oG'><fieldset id='mw4oG'></fieldset></dl></div>

                2. <small id='mw4oG'></small><noframes id='mw4oG'>