Jump to content
Android Forum - A Community For Android Users and Enthusiasts

To reference a custom view in java file and place all of them in a single XML layout file?


Recommended Posts

I would like to place a custom view in the bottom of the main.xml file.following is my Activity class and my custom view class(game.java):I want the game view to appear on the bottom of the main.xml file.Please tell me how to get on with it....I think the idea is to have a layout set in main.xml and then have the custom view on the layout.My main objective is to have the custom view appear on bottom half of main.xml layout.Please help me!!!!!




public void onCreate(Bundle savedInstanceState) {


//For custom view


RelativeLayout r=(RelativeLayout) findViewById(R.id.relative1);

g=new game(this,null);

ViewGroup vgroup=(ViewGroup) findViewById(R.id.main);


Thread mythread=new Thread(new UpdateThread());








//Game.java(custom view)

public class game extends View{



private Bitmap image;

private Paint paint;

private int x=0;private int baseY = 250;



public game(Context context,AttributeSet attrs) {



this.inflate(context, R.layout.example, null);


paint =new Paint();





public View getlay (RelativeLayout r)


return r;



public void onDraw(Canvas canvas)



canvas.drawLine(90, baseY,200,baseY, paint);






Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...