Search code examples
androidimageviewwallpaperscreen-sizetranslate-animation

Display a image larger than the device screen, and then go through the picture with a translation animation


Now I know how to make the translateAnimation, in order to go through the picture, and show it on the screen. What I do not know how to do, is put the picture on the screen, and make it in such a way so that it will not scale it by the scale type. So I can start the translateAnimation. I saw some posts about this, and a lot of suggestions are saying I should use a HorrizontalScrollView, in order to put a picture bigger than the device screen. But I need to make a animation go thought it, and not for me to be able to move the picture, so in my opinion that might not be the perfect way to go. Do you guys have any other suggestions?


Solution

  • Did not use a horrizontalScrollView, instead, forced the width of the whole layout to be the size of a picture, set a RelativeLayout inside, with the size of the screen, and then made the animations.

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:layout_width="1103dp"
    android:layout_height="736dp"
    android:background="@color/white">
    
    <ImageView
        android:id="@+id/background"
        android:visibility="invisible"
        android:src="@drawable/story1"
        android:scaleType="fitXY"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    
    <RelativeLayout
        android:id="@+id/screen_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
    -----------------CODE inside relative layout for normal page--------
    </RelativeLayout>
    
    </RelativeLayout>
    

    Then inside my code I set the screen width and height for my screen container (containing everything except the background picture which will translate):

    screenContainer.setLayoutParams(new RelativeLayout.LayoutParams(Math.round(Constants.screenWidth), Math.round(Constants.screenHeight)));
    

    This is my Translation for the ImageView that matches the parent (the size of the background pic):

     TranslateAnimation translateBackground = new TranslateAnimation(
                TranslateAnimation.RELATIVE_TO_PARENT,from,
                TranslateAnimation.RELATIVE_TO_PARENT,-0.5f,
                TranslateAnimation.RELATIVE_TO_PARENT,0.0f,
                TranslateAnimation.RELATIVE_TO_PARENT,0.0f);
        translateBackground.setDuration(15000);
        background.setVisibility(View.VISIBLE);
        background.startAnimation(translateBackground);