如何在android中以编程方式调用扩展RelativeLayout的类?

时间:2015-07-11 06:00:41

标签: java android android-layout

我通过扩展RelativeLayout在java类中创建了一个布局,并希望在单击按钮时以编程方式调用此视图。我能够像这样

在xml文件中设置自定义布局
<com.sample.CustomLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

我已经设置了以下代码的一些示例

public class Card extends RelativeLayout {

    TextView tutorialok;

    public Card(Context context) {
        super(context);
        init();
    }

    public Card(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public Card(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }
}

单击按钮时如何调用此类? 因为,我是Android的新手,一些提示或代码会有所帮助!

1 个答案:

答案 0 :(得分:1)

//custom layout is called by fully Qualified name ... package.classname
<com.sample.card
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"/>