我正在编写一个自定义视图,它是从RelativeLayout扩展而来的,我想通过编程来调整它的大小,我该怎么做?
自定义视图Class类似于:
public ActiveSlideView(Context context, AttributeSet attr){
super(context, attr);
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(inflater != null){
inflater.inflate(R.layout.active_slide, this);
}
发布于 2010-06-03 15:39:08
this.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, theSizeIWant));
问题解决了!
注意:一定要使用父布局的LayoutParams
。我的是LinearLayout.LayoutParams
!
发布于 2013-03-27 22:20:50
这对我来说很有效:
ViewGroup.LayoutParams params = layout.getLayoutParams();
params.height = customHeight;
layout.requestLayout();
发布于 2019-09-16 14:29:44
在Kotlin中,您可以使用ktx extensions
yourView.updateLayoutParams {
height = <YOUR_HEIGHT>
}
https://stackoverflow.com/questions/2963152
复制相似问题