身高和视图imageview的螺丝了setimagebitmap后 [英] Height and view of imageview screws up after setimagebitmap
问题描述
下面是我的XML:
<LinearLayout
android:id="@+id/afterphotolayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imgPreview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:maxHeight="400dp"
android:contentDescription="@string/image_description"
android:scaleType="centerCrop" />
<ImageView
android:id="@+id/blankView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
但在code,当我这样做:
But In the code, when I do this:
_imgPreview.setImageBitmap(_compressedBitmap);
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1.0f );
_imgPreview.setLayoutParams(param);
我的形象依然没有调整由中心作物占用屏幕的高度和规模的一半。看来,setImageBitmap功能螺丝钉起来的ImageView的高度/宽度,不允许它即使我尝试设置一个新的布局参数进行更改。任何人都可以提供一些线索为什么会这样?
My image is still not resized to take up half the screen height and scale by center crop. It seems that the setImageBitmap function screws up the height/width of the imageview and doesn't allow it to be changed even after I try to set a new layout param. Can anyone shed some light on why this is so?
推荐答案
我有同样的问题!快要疯了,setImageBitmap完全忽略布局权重。我还添加重量的设置编程:
I had the same issue! Was going crazy, setImageBitmap completely ignores the layout weight. I also added the setting of the weight programmatically:
barcode.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 2));
但没有帮助。
但后来我这样做:
but did not help. But then I did this:
barcode.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1, 2));
和,帮助,不给对高度的0值。我只是想这一点上棒棒糖
,所以旧版本没有测试过,但是很可能会工作。
Frustating,我花了好久再找出一些解决方法一个Android怪癖
and that helped, not giving a '0' value for the height. I just tried this out on lollipop
, so haven't tested in on older version, but will probably work.
Frustating, took me too long again to figure out some workaround for an Android quirk
这篇关于身高和视图imageview的螺丝了setimagebitmap后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!