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

布局对应的xml

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
>
             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"
     />

 

代码中

   private   TextView     tv;

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

   RelativeLayout对应xml控件的父布局。

 

转载于:https://www.cnblogs.com/lgy0069/p/5286655.html

你可能感兴趣的:(android中动态的设置距left,right,top,bottom)