android中动态的设置距left,right,top,bottom

布局对应的xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
>
      <TextView
       android:id="@+id/tv"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:gravity="center"
       android:textSize="18sp"
       android:text="和讯"
       android:textColor="@color/yellow"
      android:layout_alignParentBottom="true"
     />
</RelativeLayout>

 

代码中

   private   TextView     tv;

   tv=(TextView) findViewById(R.id.tv);
   RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) tv.getLayoutParams();
   layoutParams.bottomMargin=20;
   tv.setLayoutParams(layoutParams);

   RelativeLayout对应xml控件的父布局。

 

posted @ 2016-03-17 11:25  冰封传情  阅读(2020)  评论(0编辑  收藏  举报