Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

move a image partially out of the screen in android

Tags:

android

I have an ImageView in android. I want to move the image partially inside the screen such that only a part of the image is visible. If I set margin or padding in xml the image shrinks. I used a translate Animation in onCreate method. But I see image moving the first time the view is presented. I want the image to be partially visible without the shift being visible. Is there any way of doing this?

like image 550
user866821 Avatar asked Aug 30 '11 22:08

user866821


People also ask

How do I set a picture on my Android without stretching it?

Have a look at some of the proposed suggestions for similar questions: ImageView one dimension to fit free space and second evaluate to keep aspect ration. Fit image into ImageView, keep aspect ratio and then resize ImageView to image dimensions? Resizing ImageView to fit to aspect ratio.

How to animate View in Android studio?

You can use the view animation system to perform tweened animation on Views. Tween animation calculates the animation with information such as the start point, end point, size, rotation, and other common aspects of an animation.


2 Answers

in the parent view (like LinearView) set ClipChildrens=false, if what you are looking for

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>
like image 179
Mohammad Ersan Avatar answered Nov 15 '22 00:11

Mohammad Ersan


How about this.

In your Activity's onCreate:

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

That way, it is positioned properly at startup. Or you could use an AbsoluteLayout and set the image's x and y coordinates that way. Make sure you arent using fill_parent for either the height or width.

like image 42
Delete Avatar answered Nov 14 '22 23:11

Delete