【问题标题】:Image is not setting to fill_parent in Imageview图像未在 Imageview 中设置为 fill_parent
【发布时间】:2012-12-05 19:36:13
【问题描述】:

即使我将 (android:layout_width="fill_parent") 给我的 Imageview 类,图像也没有全宽显示

<ImageView android:id="@+id/img"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
     android:layout_above="@+id/button_layout"
    android:layout_below="@+id/middle1"
      />  

这里我得到了我的位图

 if (orientation != 0) {
                        Matrix matrix = new Matrix();
                        matrix.postRotate(orientation);
                        bMapRotate = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(),
                                bmp.getHeight(), matrix, true);
                    } else
                        bMapRotate = Bitmap.createScaledBitmap(bmp, bmp.getWidth(),
                                bmp.getHeight(), true);
                    findViewById(R.id.img).setVisibility(View.VISIBLE);
//Here I set the bitmap                 ((ImageView)findViewById(R.id.img)).setImageBitmap(bMapRotate);
                    findViewById(R.id.preview).setVisibility(View.GONE);

我无法理解为什么它没有占据整个屏幕长度,即使我在我的 xml 中将 fill_parent 赋予 imageview

【问题讨论】:

  • 尝试使用比例属性
  • 你在做setImageBitmap吗??和你使用矩阵的位图??
  • 你在做什么?你想在改变方向时缩放与设备屏幕尺寸相同的图像吗?
  • 你的 ImageView 的父布局是什么?你能从你的 xml 布局中发布更多的片段吗?

标签: android android-layout android-imageview


【解决方案1】:

查看 ImageView 的 scaleType 元素。我想你可能想要 fitXY...

【讨论】:

    【解决方案2】:
      setScaleType(ImageView.ScaleType.MATRIX);
    

    在你的 ImageView 上试试这个,并确保你的位图在创建后返回相同的宽度到 ScreenWidth

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-16
      • 1970-01-01
      • 1970-01-01
      • 2018-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多