relativelayout - How set android:layout_marginBottom programm? -
to drag image on screen created own class:
private class customimageview extends appcompatimageview
in constructor want set params:
public customimageview(context context) { super(context); params = new relativelayout.layoutparams(relativelayout.layoutparams.match_parent, relativelayout.layoutparams.match_parent); params.bottommargin = 50; this.setscaletype(imageview.scaletype.center_crop); this.setlayoutparams(params); this.setwillnotdraw(false); }
my activity_main.xml:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.eleizo.firstapplication.mainactivity"> </relativelayout>
i want have :
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.eleizo.firstapplication.mainactivity"> <imageview android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" android:scaletype="centercrop" android:layout_marginbottom="50dp" /> </relativelayout>
why string "params.bottommargin = 50"
doesn't work? tried set params = new relativelayout.layoutparams(val1,val2)
it's no matter. how set android:layout_marginbottom
in relativelayout code?
try using layoutparams while adding view in relative layout. viewgroup.addview(view, layoutparams) .
something this.
relativelayout.layoutparams params = new relativelayout.layoutparams(relativelayout.layoutparams.match_parent, relativelayout.layoutparams.match_parent); params.bottommargin = 50; relativelayout.addview(new cutomimageview(context), params);
Comments
Post a Comment