Reputation: 15128
i have RelativeLayout, and there is a textview in the RelativeLayout, i am getting position from server like ALIGN_PARENT_LEFT, ALIGN_PARENT_TOP, based on that value i want to change position of textview...
My xml file is....
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:id="@+id/relativelayout"
android:orientation="vertical" >
<TextView
android:id="@+id/share_text"
android:layout_width="100dp"
android:layout_height="60dp"
android:gravity="center"
android:background="@drawable/share_text" />
</RelativeLayout>
i have got knowledge from Set position of an EditText and TextView in a RelativeLayout programatically to chage the position but couldn't help me
can any body help me how to change position of textview dynamically...
Upvotes: 3
Views: 6236
Reputation: 22493
try like this
RelativeLayout.LayoutParams params1 = new
RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params1.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
yourTextview.setLayoutParams(params1);
Upvotes: 5
Reputation: 4458
what about
((RelativeLayout.LayoutParams)yourView.getLayoutParams()).alignParentTop =
serverResponse.equals("ALIGN_PARENT_TOP");
?
Of course you have to do some parsing of your server response, etc...
Upvotes: 2