Change TextView's position dynamically using j

2019-07-05 12:38发布

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

2条回答
Emotional °昔
2楼-- · 2019-07-05 13:21

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);
查看更多
Bombasti
3楼-- · 2019-07-05 13:25

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

查看更多
登录 后发表回答