本文介绍了安卓:视图的设置最小高度编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图以编程方式设置最小高度为ImageView的,但没有运气至今。我的code是低于
I'm trying to set minimum height for an imageview programmatically but had no luck so far. My code is below
int width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 160, getResources().getDisplayMetrics());
int minHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, getResources().getDisplayMetrics());
LayoutParams params = new LayoutParams(width,LayoutParams.MATCH_PARENT);
SmartImageView siv = new SmartImageView(getActivity());
siv.setMinimumHeight(minHeight);
siv.setLayoutParams(sivParams);
siv.setAdjustViewBounds(true);
siv.setScaleType(ScaleType.FIT_XY);
siv.setImageUrl(url);
ll.addView(siv);
我也试过把setMinimumWidth方法setLayoutParams方法后,但没有任何工作。请帮助
I also tried to put the setMinimumWidth method after the setLayoutParams method but that didn't worked either. Please help
感谢
推荐答案
试试这个--->
siv.getLayoutParams().height = minHeight;
或u还可以尝试--->
or u can also try--->
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(width , minHeight);
siv.setLayoutParams(layoutParams);
这篇关于安卓:视图的设置最小高度编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!