ram
ram

Reputation: 1121

Android relative layout

I've a relative layout in xml. I have to add some textview programatically to view, now I've to align a textview as alignparentright.I can do this only using .addRule() but I don't want to create a relative layout programmatically and then use this layer object.addRule().Instead I've already added an id to relativeview in xml.

How do i use addRule() in this xml relative layer.I got the id in activity using findviewbyid and assigned to type textview but when i do textview.addRule(), this is not there for this relative layout type variable.

Upvotes: 1

Views: 373

Answers (1)

Android Killer
Android Killer

Reputation: 18489

Simple, go like this

    RelativeLayout rl = (RelativeLayout)findViewById(R.id.relative_layout_id);
    RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    TextView tv = new TextView(this);
    tv.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    rl.addView(tv);

Any problem plz ask.

Upvotes: 1

Related Questions