Siddhpura Amit
Siddhpura Amit

Reputation: 15128

Dynamically put textview above another view in relativelayout android

Hi by doing java code i have done successfully add textview in relative layout like BOTTOM|RIGHT

but i want to put textview above bottom bar layout

here is the image enter image description here

here u can see that there is a textview which has white background image and its back it has black bottom baar i want to put textview above's bottom bar

Below is my java code

 LinearLayout bottomBar = (LinearLayout)findViewById(R.id.bottomBar);
    RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(150, 70);
    params1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    params1.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
    params1.addRule(RelativeLayout.ABOVE, bottomBar.getId());
    butAddText.setLayoutParams(params1);

By doing this i have added bottom left but last two lines is not working i can not add textview above the bottom bar..

can any body help me please

Upvotes: 2

Views: 3566

Answers (2)

android developer
android developer

Reputation: 116080

I suspect the problem is that you've set 2 conflicting rules.

Try to remove the next line:

params1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);

The reason: you've tried to set the view to the bottom of its parent, and also above another view.

Upvotes: 2

hasanghaforian
hasanghaforian

Reputation: 14042

Simplest way may be simulate nested layouts:

<LinearLayout ...>
<TextView/>
<RelativeLayout/>
</LinearLayout>

But it may decrease performance.

Edit:

First inflate your LinearLayout(it's orientation is vertically) then add your TextView and your bottom bar.Also if you want to align TextView right,you can use a RealtiveLayout instead of outer LinearLayout.

Upvotes: 0

Related Questions