我有RelativeLayout,并且在RelativeLayout中有一个textview,我从服务器获取位置,如ALIGN_PARENT_LEFT,ALIGN_PARENT_TOP,基于该值我想要更改textview的位置… 我的xml文件是…. ?xml version="1.0" encoding="utf-8"?Re
我的xml文件是….
<?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>
我从Set position of an EditText and TextView in a RelativeLayout programatically获得了知识,但是无法帮助我
任何人都可以帮助我动态地改变textview的位置……
试试这样RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params1.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); yourTextview.setLayoutParams(params1);