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

问题描述

我编码的自定义视图,从RelativeLayout的延伸,我希望以编程方式调整其大小,我该怎么办?

在自定义视图类是这样的:

 公共ActiveSlideView(上下文的背景下,的AttributeSet attr)使用{
        超(背景下,ATTR);
        LayoutInflater充气=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        如果(充气!= NULL){
            inflater.inflate(R.layout.active_slide,这一点);
        }
 

解决方案

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

问题解决了!

请注意:一定要使用父布局的的LayoutParams 。我的是 LinearLayout.LayoutParams

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

the custom view Class is something like:

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

Problem solved!

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

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

07-02 11:29