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?


vyshas
 Share

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!!!!!

//LearningActivity.java

 

 

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

//For custom view

setContentView(R.layout.main);

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

g=new game(this,null);

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

vgroup.addView(g);

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

mythread.start();

 

 

}

 

 

 

//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) {

super(context,attrs);

 

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

image=Bitmap.createBitmap(BitmapFactory.decodeResource(this.getResources(),R.drawable.ic_launcher));

paint =new Paint();

paint.setColor(Color.BLUE);

 

}

 

public View getlay (RelativeLayout r)

{

return r;

}

 

public void onDraw(Canvas canvas)

{

super.onDraw(canvas);

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

canvas.drawLine(125,baseY,125,baseY-100,paint);

canvas.drawLine(110,baseY,125,baseY-15,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.

Guest
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.

Loading...
 Share

×
×
  • Create New...