Move image partially from screen in android

Android has ImageView . I want to partially move the image inside the screen so that only part of the image is displayed. If I set margin or padding to xml, the image is compressed. I used the Animation translation method in onCreate . But I see the image moving on the first view of the view. I want the image to be partially visible without the appearance of a shift. Is there any way to do this?

+6
source share
3 answers

in parent view (e.g. LinearView ) set ClipChildrens=false if you are looking

check this code, it works for me ...

 <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_marginRight="-20dp" android:src="@drawable/ic_launcher" /> </FrameLayout> 
+4
source

How about this one.

In your onCreate activity:

 ImageView yourImage = (ImageView)findViewById(R.id.your_image_control_id); yourImage.setX(1000); yourImage.setY(1000); 

Thus, it is correctly positioned at startup. Or you can use AbsoluteLayout and set the x and y image coordinates this way. Make sure that arent using fill_parent for height or width.

+2
source

I found that if you use negative fields, you cannot align the Parent from the opposite side, so let it say that you are trying to make the image half open on the right side of the view, you cannot specify android: layout_alignParentLeft. In addition, if you need a full image and you do not want it to be cropped, as in the case when you wanted to animate onClick in full screen, you need to set the android parent layout: clipChildren = "false". The following xml def works for me:

 <ImageView android:id="@+id/you_feature_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginRight="@dimen/feature_margin_right" android:contentDescription="feature_image" android:gravity="center_vertical" android:padding="@dimen/zero" android:paddingBottom="@dimen/zero" android:paddingLeft="@dimen/zero" android:paddingRight="@dimen/zero" android:paddingTop="@dimen/zero" android:src="@drawable/feature_phone_02_2x" /> 

I am posting this now because I just burned for several hours trying to figure it out myself and thought that maybe this will help someone else in the future if they come across this issue like me.

+2
source

Source: https://habr.com/ru/post/896261/


All Articles