如何以编程方式调整自定义视图的大小? [英] How to resize a custom view programmatically?

查看:70
本文介绍了如何以编程方式调整自定义视图的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编码自RelativeLayout扩展的自定义视图,并且我想以编程方式调整它的大小,该怎么办?

I am coding a custom view, extended from RelativeLayout, and I want to resize it programmatically, How can I do?

自定义视图类类似于:

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);
        }

推荐答案

this.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, theSizeIWant));

问题解决了!

注意:确保使用父版面的LayoutParams.我的是LinearLayout.LayoutParams

NOTE: Be sure to use the parent Layout's LayoutParams. Mine is LinearLayout.LayoutParams!

这篇关于如何以编程方式调整自定义视图的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆