gpt4 book ai didi

Android通过java代码prob将wrap_content设置为ImageView

转载 作者:行者123 更新时间:2023-11-29 21:57:29 25 4
gpt4 key购买 nike

我已经将位图设置为 ImageView,然后想为宽度和高度设置 wrap_content。

imgSubsegment = (ImageView) findViewById(R.id.subsegment);

ViewGroup.LayoutParams imageViewParams = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);

......................................

imgSubsegmentSensor.setImageBitmap(bmpSubsegmentSensor);
imgSubsegmentSensor.setLayoutParams(imageViewParams);

它给出 java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.view.ViewGroup$MarginLayoutParams

我的代码有什么问题?如何解决?

最佳答案

    imgSubsegment = (ImageView) findViewById(R.id.subsegment);

ViewGroup.MarginLayoutParams imageViewParams = new ViewGroup.MarginLayoutParams(
ViewGroup.MarginLayoutParams.WRAP_CONTENT,
ViewGroup.MarginLayoutParams.WRAP_CONTENT);

......................................

imgSubsegmentSensor.setImageBitmap(bmpSubsegmentSensor);
imgSubsegmentSensor.setLayoutParams(imageViewParams);

试试这个。

关于Android通过java代码prob将wrap_content设置为ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12896919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com