类滑块android

类滑块android,android,slider,Android,Slider,我创建了这个类,它从LinearLayout扩展而来。它可以帮助我在按下按钮时显示或隐藏某些组件。 我有这样一个错误:“android.widget.RelativeLayout中没有默认构造函数”;即使我创建了默认构造函数 public class Slider extends LinearLayout { private Boolean isOpen; private RelativeLayout toHide; private static int SPE

我创建了这个类,它从LinearLayout扩展而来。它可以帮助我在按下按钮时显示或隐藏某些组件。 我有这样一个错误:“android.widget.RelativeLayout中没有默认构造函数”;即使我创建了默认构造函数

 public class Slider extends LinearLayout {

     private Boolean isOpen;
     private RelativeLayout toHide;
     private static int SPEED;


     public boolean toggle() {
        TranslateAnimation animation = null;
        isOpen = !isOpen;

        if (isOpen)
        {
            animation = new TranslateAnimation(0.0f, 0.0f, -toHide.getHeight(), 0.0f);
            animation.setAnimationListener(openListener);

        } else
        {
            animation = new TranslateAnimation(0.0f, 0.0f, 0.0f, - toHide.getHeight());
            animation.setAnimationListener(closeListener);

        }

        animation.setDuration(SPEED);
        animation.setInterpolator(new AccelerateInterpolator());
        startAnimation(animation);

        return isOpen;
    }
}

错误实际上告诉您的是,由于您要扩展的类(
LinearLayout
)没有无参数构造函数,因此您的类需要显式声明一个构造函数,以便可以调用具有参数的
super()
构造函数之一

对于视图,通常第一个参数是
上下文
对象,因此如果添加这样的构造函数,错误将消失:

public Slider(Context context) {
    super(context);
}
我有一个错误:“无法解析符号‘内容’。