开发者

can we use layout in Customview?

开发者 https://www.devze.com 2023-01-04 07:02 出处:网络
friends, i have a custom view class public class Zoom extends View { private Drawable image; private int zoomControler=20;

friends,

i have a custom view class

public class Zoom extends View {
        private Drawable image;
        private int zoomControler=20; 
        public Zoom(Context context)
        {
            super(context);
            image=context.getResources().getDrawable(R.drawable.icon);
            setFocusable(true);

        }
        @Override
        protected void onDraw(Canvas canvas) {

            super.onDraw(canvas);

            //TransparentPanel tp = new TransparentPanel(this.getContext());

            //Button MyButton = new Button(this.getContext());
            //MyButton.setText("Press me");

            //tp.addView(MyBut开发者_高级运维ton);

            image.setBounds((getWidth()/2)-zoomControler, (getHeight()/2)-zoomControler, (getWidth()/2)+zoomControler, (getHeight()/2)+zoomControler);
            image.draw(canvas);




        }

}

can i use SetContentView(R.layout.mylayout) in this custom view to display that design?

or

how can i display button with image ondraw method as i have commented the code ?

any help would be appreciated.


In that case you will have to create a custom XML in the res/layout dir:

<?xml version="1.0" encoding="utf-8"?>
<your.package.Zoom xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />

As you want to use R.layout.mylayout the XML file will have to be called mylayout.xml

0

精彩评论

暂无评论...
验证码 换一张
取 消