pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

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

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

        <legend id='TkWLe'><style id='TkWLe'><dir id='TkWLe'><q id='TkWLe'></q></dir></style></legend>
      1. <tfoot id='TkWLe'></tfoot>

        使用 ImageView 顯示 AlertDialog 而無需任何填充

        Show AlertDialog with ImageView without any padding(使用 ImageView 顯示 AlertDialog 而無需任何填充)
        <i id='WYaRs'><tr id='WYaRs'><dt id='WYaRs'><q id='WYaRs'><span id='WYaRs'><b id='WYaRs'><form id='WYaRs'><ins id='WYaRs'></ins><ul id='WYaRs'></ul><sub id='WYaRs'></sub></form><legend id='WYaRs'></legend><bdo id='WYaRs'><pre id='WYaRs'><center id='WYaRs'></center></pre></bdo></b><th id='WYaRs'></th></span></q></dt></tr></i><div class="rp5vltv" id='WYaRs'><tfoot id='WYaRs'></tfoot><dl id='WYaRs'><fieldset id='WYaRs'></fieldset></dl></div>
          <bdo id='WYaRs'></bdo><ul id='WYaRs'></ul>
          • <legend id='WYaRs'><style id='WYaRs'><dir id='WYaRs'><q id='WYaRs'></q></dir></style></legend>

              <tbody id='WYaRs'></tbody>

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

              1. <tfoot id='WYaRs'></tfoot>

                • 本文介紹了使用 ImageView 顯示 AlertDialog 而無需任何填充的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  編輯 - 解決方案:

                  我最終找到了解決此問題的方法.因?yàn)槭謩?dòng)更改 ImageView 的高度會(huì)刪除額外的填充,所以我最終找到了原始圖像的尺寸,并在可以計(jì)算 ImageView 尺寸后將它們應(yīng)用于 ImageView.這是最終結(jié)果:

                  I ended up figuring out a way to solve this issue. Because manually changing the height of the ImageView removes the extra padding, I ended up finding the dimensions of the original image, and apply them to the ImageView once the ImageView dimensions can be calculated. Here is the final result:

                  這是最終的工作代碼:

                  AlertDialog.Builder builder = new AlertDialog.Builder(this);
                          builder.setPositiveButton("Get Pro", new DialogInterface.OnClickListener() {
                              @Override
                              public void onClick(DialogInterface dialog, int which) {
                              }
                          }).setNegativeButton("No thanks", new DialogInterface.OnClickListener() {
                              @Override
                              public void onClick(DialogInterface dialog, int which) {
                              }
                          });
                          final AlertDialog dialog = builder.create();
                          LayoutInflater inflater = getLayoutInflater();
                          View dialogLayout = inflater.inflate(R.layout.go_pro_dialog_layout, null);
                          dialog.setView(dialogLayout);
                          dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                  
                          dialog.show();
                  
                          dialog.setOnShowListener(new DialogInterface.OnShowListener() {
                              @Override
                              public void onShow(DialogInterface d) {
                                  ImageView image = (ImageView) dialog.findViewById(R.id.goProDialogImage);
                                  Bitmap icon = BitmapFactory.decodeResource(context.getResources(),
                                          R.drawable.whygoprodialogimage);
                                  float imageWidthInPX = (float)image.getWidth();
                  
                                  LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(Math.round(imageWidthInPX),
                                          Math.round(imageWidthInPX * (float)icon.getHeight() / (float)icon.getWidth()));
                                  image.setLayoutParams(layoutParams);
                  
                  
                              }
                          });
                  

                  還有 XML:

                  <?xml version="1.0" encoding="utf-8"?>
                  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                      android:orientation="vertical"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content">
                  
                      <ImageView
                          android:id="@+id/goProDialogImage"
                          android:layout_width="wrap_content"
                          android:layout_height="350dp"
                          android:src="@drawable/whygoprodialogimage"/>
                  
                  </LinearLayout>
                  

                  原始問題:

                  我的目標(biāo)是有一個(gè) AlertDialog ,它有一個(gè) ImageView 占據(jù)整個(gè)對(duì)話框,保留它的尺寸,加上兩個(gè)按鈕.通過標(biāo)準(zhǔn)方法實(shí)現(xiàn),如下所示:

                  My goal is to have an AlertDialog that has an ImageView that takes up the whole dialog, retaining it's dimensions, plus two buttons. By implementing it through standard methods, it looks like the following:

                  我正在嘗試消除它上方和下方的填充.下面是它的設(shè)置代碼:

                  I am trying to eliminate that padding above and below it. Here's the code for how it's set up:

                  布局:

                  <?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="wrap_content">
                  
                      <ImageView
                          android:id="@+id/goProDialogImage"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:src="@drawable/whygoprodialogimage"/>
                  
                  </LinearLayout>
                  

                  代碼:

                  AlertDialog.Builder builder = new AlertDialog.Builder(this);
                          builder.setPositiveButton("Get Pro", new DialogInterface.OnClickListener() {
                              @Override
                              public void onClick(DialogInterface dialog, int which) {
                              }
                          }).setNegativeButton("No thanks", new DialogInterface.OnClickListener() {
                              @Override
                              public void onClick(DialogInterface dialog, int which) {
                              }
                          });
                          AlertDialog dialog = builder.create();
                          LayoutInflater inflater = getLayoutInflater();
                          View dialogLayout = inflater.inflate(R.layout.go_pro_dialog_layout, null);
                          dialog.setView(dialogLayout);
                          dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                  
                          dialog.show();
                  

                  查看this StackOverflow answer后,我嘗試實(shí)施該解決方案,因?yàn)樗麄兊膯栴}似乎相似,但即使它是更接近我現(xiàn)在想要的結(jié)果如下所示:

                  After looking at this StackOverflow answer, I tried implementing that solution because their problem seemed similar, but even though it is closer to what I want now the result looks like this:

                  所以它消除了填充,但圖像看起來被壓扁了.這是此潛在修復(fù)實(shí)現(xiàn)的代碼:

                  So it eliminated the padding but the image looks squished. Here's the code for this potential fix implementation:

                  // Get screen size
                          Display display = getWindowManager().getDefaultDisplay();
                          Point size = new Point();
                          display.getSize(size);
                          int screenWidth = size.x;
                          int screenHeight = size.y;
                  
                          // Get target image size
                          Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.whygoprodialogimage);
                          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 resizedDialogImage = new BitmapDrawable(context.getResources(), Bitmap.createScaledBitmap(bitmap, bitmapWidth, bitmapHeight, false));
                  
                          AlertDialog.Builder builder = new AlertDialog.Builder(this);
                          builder.setPositiveButton("Get Pro", new DialogInterface.OnClickListener() {
                              @Override
                              public void onClick(DialogInterface dialog, int which) {
                  
                              }
                          }).setNegativeButton("No thanks", new DialogInterface.OnClickListener() {
                              @Override
                              public void onClick(DialogInterface dialog, int which) {
                              }
                          });
                          AlertDialog dialog = builder.create();
                          LayoutInflater inflater = getLayoutInflater();
                          View dialogLayout = inflater.inflate(R.layout.go_pro_dialog_layout, null);
                          dialog.setView(dialogLayout);
                          dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                  
                          // Without this line there is a very small border around the image (1px)
                          dialog.getWindow().setBackgroundDrawable(null);
                  
                          dialog.show();
                          ImageView image = (ImageView) dialog.findViewById(R.id.goProDialogImage);
                          image.setBackground(resizedDialogImage);
                  

                  是什么導(dǎo)致圖像現(xiàn)在看起來被壓扁了?你可以看出它去掉了額外的填充,但圖像尺寸發(fā)生了變化.

                  What is it that is causing the image to now look squished? You can tell it got rid of the extra padding but the image dimensions are changed.

                  推薦答案

                  我最終找到了解決這個(gè)問題的方法.因?yàn)槭謩?dòng)更改 ImageView 的高度會(huì)刪除額外的填充,所以我最終找到了原始圖像的尺寸,并在可以計(jì)算 ImageView 尺寸后將它們應(yīng)用于 ImageView.這是最終結(jié)果:

                  I ended up figuring out a way to solve this issue. Because manually changing the height of the ImageView removes the extra padding, I ended up finding the dimensions of the original image, and apply them to the ImageView once the ImageView dimensions can be calculated. Here is the final result:

                  這是最終的工作代碼:

                  AlertDialog.Builder builder = new AlertDialog.Builder(this);
                          builder.setPositiveButton("Get Pro", new DialogInterface.OnClickListener() {
                              @Override
                              public void onClick(DialogInterface dialog, int which) {
                              }
                          }).setNegativeButton("No thanks", new DialogInterface.OnClickListener() {
                              @Override
                              public void onClick(DialogInterface dialog, int which) {
                              }
                          });
                          final AlertDialog dialog = builder.create();
                          LayoutInflater inflater = getLayoutInflater();
                          View dialogLayout = inflater.inflate(R.layout.go_pro_dialog_layout, null);
                          dialog.setView(dialogLayout);
                          dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                  
                          dialog.show();
                  
                          dialog.setOnShowListener(new DialogInterface.OnShowListener() {
                              @Override
                              public void onShow(DialogInterface d) {
                                  ImageView image = (ImageView) dialog.findViewById(R.id.goProDialogImage);
                                  Bitmap icon = BitmapFactory.decodeResource(context.getResources(),
                                          R.drawable.whygoprodialogimage);
                                  float imageWidthInPX = (float)image.getWidth();
                  
                                  LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(Math.round(imageWidthInPX),
                                          Math.round(imageWidthInPX * (float)icon.getHeight() / (float)icon.getWidth()));
                                  image.setLayoutParams(layoutParams);
                  
                  
                              }
                          });
                  

                  還有 XML:

                  <?xml version="1.0" encoding="utf-8"?>
                  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                      android:orientation="vertical"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content">
                  
                      <ImageView
                          android:id="@+id/goProDialogImage"
                          android:layout_width="wrap_content"
                          android:layout_height="350dp"
                          android:src="@drawable/whygoprodialogimage"/>
                  
                  </LinearLayout>
                  

                  這篇關(guān)于使用 ImageView 顯示 AlertDialog 而無需任何填充的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Get user#39;s current location using GPS(使用 GPS 獲取用戶的當(dāng)前位置)
                  IllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 拋出的 IllegalArgumentException)
                  How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?)
                  How to detect Location Provider ? GPS or Network Provider(如何檢測(cè)位置提供者?GPS 或網(wǎng)絡(luò)提供商)
                  Get current location during app launch(在應(yīng)用啟動(dòng)期間獲取當(dāng)前位置)
                  locationManager.getLastKnownLocation() return null(locationManager.getLastKnownLocation() 返回 null)

                  <legend id='bEWve'><style id='bEWve'><dir id='bEWve'><q id='bEWve'></q></dir></style></legend>
                    <tbody id='bEWve'></tbody>
                    <i id='bEWve'><tr id='bEWve'><dt id='bEWve'><q id='bEWve'><span id='bEWve'><b id='bEWve'><form id='bEWve'><ins id='bEWve'></ins><ul id='bEWve'></ul><sub id='bEWve'></sub></form><legend id='bEWve'></legend><bdo id='bEWve'><pre id='bEWve'><center id='bEWve'></center></pre></bdo></b><th id='bEWve'></th></span></q></dt></tr></i><div class="pl7ltnz" id='bEWve'><tfoot id='bEWve'></tfoot><dl id='bEWve'><fieldset id='bEWve'></fieldset></dl></div>

                    <tfoot id='bEWve'></tfoot>

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

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

                            主站蜘蛛池模板: 膜结构车棚|上海膜结构车棚|上海车棚厂家|上海膜结构公司 | 清管器,管道清管器,聚氨酯发泡球,清管球 - 承德嘉拓设备 | 上海租车公司_上海包车_奔驰租赁_上海商务租车_上海谐焕租车 | 磁力抛光机_磁力研磨机_磁力去毛刺机_精密五金零件抛光设备厂家-冠古科技 | 上海办公室装修_上海店铺装修公司_厂房装潢设计_办公室装修 | 众品家具网-家具品牌招商_家具代理加盟_家具门户的首选网络媒体。 | 行业分析:提及郑州火车站附近真有 特殊按摩 ?2025实地踩坑指南 新手如何避坑不踩雷 | 超声骨密度仪,双能X射线骨密度仪【起草单位】,骨密度检测仪厂家 - 品源医疗(江苏)有限公司 | 智能终端_RTU_dcm_北斗星空自动化科技| 丹佛斯变频器-丹佛斯压力开关-变送器-广州市风华机电设备有限公司 | 胃口福饺子加盟官网_新鲜现包饺子云吞加盟 - 【胃口福唯一官网】 | 企小优-企业数字化转型服务商_网络推广_网络推广公司 | 龙门加工中心-数控龙门加工中心厂家价格-山东海特数控机床有限公司_龙门加工中心-数控龙门加工中心厂家价格-山东海特数控机床有限公司 | 长沙发电机-湖南发电机-柴油发电机供应厂家-长沙明邦智能科技 | 芝麻黑-芝麻黑石材厂家-永峰石业| 空调风机,低噪声离心式通风机,不锈钢防爆风机,前倾皮带传动风机,后倾空调风机-山东捷风风机有限公司 | 工程管道/塑料管材/pvc排水管/ppr给水管/pe双壁波纹管等品牌管材批发厂家-河南洁尔康建材 | 集装箱箱号识别_自重载重图像识别_铁路车号自动识别_OCR图像识别 | 武汉森源蓝天环境科技工程有限公司-为环境污染治理提供协同解决方案 | 旗杆生产厂家_不锈钢锥形旗杆价格_铝合金电动旗杆-上海锥升金属科技有限公司 | 全自动真空上料机_粉末真空上料机_气动真空上料机-南京奥威环保科技设备有限公司 | 盘装氧量分析仪-防爆壁挂氧化锆分析仪-安徽吉帆仪表有限公司 | CNC机加工-数控加工-精密零件加工-ISO认证厂家-鑫创盟 | 超细粉碎机|超微气流磨|气流分级机|粉体改性设备|超微粉碎设备-山东埃尔派粉碎机厂家 | 薪动-人力资源公司-灵活用工薪资代发-费用结算-残保金优化-北京秒付科技有限公司 | 骨密度仪-骨密度测定仪-超声骨密度仪-骨龄测定仪-天津开发区圣鸿医疗器械有限公司 | 螺旋丝杆升降机-SWL蜗轮-滚珠丝杆升降机厂家-山东明泰传动机械有限公司 | 出国劳务公司_正规派遣公司[严海] | 郑州巴特熔体泵有限公司专业的熔体泵,熔体齿轮泵与换网器生产厂家 | 制丸机,小型中药制丸机,全自动制丸机价格-甘肃恒跃制药设备有限公司 | 江苏皓越真空设备有限公司 | 千斤顶,液压千斤顶-力良企业,专业的液压千斤顶制造商,shliliang.com | 上海刑事律师|刑事辩护律师|专业刑事犯罪辩护律师免费咨询-[尤辰荣]金牌上海刑事律师团队 | 苏州伊诺尔拆除公司_专业酒店厂房拆除_商场学校拆除_办公楼房屋拆除_家工装拆除拆旧 | 超声波破碎仪-均质乳化机(供应杭州,上海,北京,广州,深圳,成都等地)-上海沪析实业有限公司 | 食安观察网| 泰来华顿液氮罐,美国MVE液氮罐,自增压液氮罐,定制液氮生物容器,进口杜瓦瓶-上海京灿精密机械有限公司 | 无菌水质袋-NASCO食品无菌袋-Whirl-Pak无菌采样袋-深圳市慧普德贸易有限公司 | 蒸汽热收缩机_蒸汽发生器_塑封机_包膜机_封切收缩机_热收缩包装机_真空机_全自动打包机_捆扎机_封箱机-东莞市中堡智能科技有限公司 | 世界箱包品牌十大排名,女包小众轻奢品牌推荐200元左右,男包十大奢侈品牌排行榜双肩,学生拉杆箱什么品牌好质量好 - Gouwu3.com | 气体检测仪-氢气检测仪-可燃气体传感器-恶臭电子鼻-深国安电子 |