Android, why adding left/right margin scales up image? -
i have 2 image views, 1 on top of other. behind imageview displays user's image while top 1 cover image (just face area transparent following screenshot).
my layout this:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/rlcontainer"> <imageview android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/ivuserimage" android:contentdescription="@string/content_description"/> <imageview android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/ivcoverimage" android:contentdescription="@string/content_description" android:scaletype="fitxy"/> </relativelayout>
i'm using onswipetouchlistener class in order adjust user's shape in transparent (face) area. have following code in oncreateview() of fragment:
mrlcontainer = (relativelayout) view.findviewbyid(r.id.rlcontainer); muserimage = (imageview) view.findviewbyid(r.id.ivuserimage); muserimage.setimageuri(mimguri); mcoverimage = (imageview) view.findviewbyid(r.id.ivcoverimage); mcoverimage.setontouchlistener(new onswipetouchlistener(mcontext) { public void onswipetop() { moveimagetotop(); } public void onswiperight() { moveimagetoright(); } public void onswipeleft() { moveimagetoleft(); } public void onswipebottom() { moveimagetobottom(); } public boolean ontouch(view v, motionevent event) { return getgesturedetector().ontouchevent(event); } });
and movement methods these:
private void moveimagetotop() { layoutparams layoutparams = (layoutparams) muserimage.getlayoutparams(); layoutparams.topmargin -= 20; muserimage.setlayoutparams(layoutparams); } private void moveimagetobottom() { layoutparams layoutparams = (layoutparams) muserimage.getlayoutparams(); layoutparams.bottommargin -= 20; muserimage.setlayoutparams(layoutparams); } private void moveimagetoright() { layoutparams layoutparams = (layoutparams) muserimage.getlayoutparams(); layoutparams.rightmargin -= 20; muserimage.setlayoutparams(layoutparams); } private void moveimagetoleft() { layoutparams layoutparams = (layoutparams) muserimage.getlayoutparams(); layoutparams.leftmargin -= 20; muserimage.setlayoutparams(layoutparams); }
now, moveimagetotop() , moveimagetobottom() working fine when touch screen , move finger top or bottom. however, image scales when move left or right.
what think? mistake? suggestion appreciated. thanks
as know, default image scaletype fit_center. didn't change position since set match_parent in both axis. change view boundaries. changing vertical boundaries didn't change image size inside imageview if image fit in horizontal axis.
if you, use animation framework or change position during onlayout change , ask relayout after every swipe.
Comments
Post a Comment