Change TextView's position dynamically using java in RelativeLayout android

android, android-relativelayout, java, layout

Solution

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);

Problem

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

Original source