Created
September 3, 2018 09:13
-
-
Save Onwa1kenobi/ef9e6926a1dfb9a590b7dce3280beab3 to your computer and use it in GitHub Desktop.
View pager parallax transformation effect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<android.support.design.widget.CoordinatorLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<ImageView | |
android:id="@+id/image" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:adjustViewBounds="true" | |
android:contentDescription="@string/description_image" | |
android:scaleType="centerCrop" /> | |
</android.support.design.widget.CoordinatorLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.voidloop.peepscreen.lockscreen; | |
import android.support.v7.app.AppCompatActivity; | |
import android.support.v4.view.ViewPager; | |
public class LockscreenActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
ViewPager viewPager = view.findViewById(R.id.viewpager); | |
viewPager.setPageTransformer(false, new PageTransformer()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.voidloop.peepscreen.lockscreen; | |
import android.support.annotation.NonNull; | |
import android.support.v4.view.ViewPager; | |
import android.view.View; | |
import android.widget.ImageView; | |
import com.voidloop.peepscreen.R; | |
/* | |
* Created by ameh on 13/10/2017. | |
*/ | |
public class PageTransformer implements ViewPager.PageTransformer { | |
@Override | |
public void transformPage(@NonNull View page, float position) { | |
int pageWidth = page.getWidth(); | |
ImageView image = page.findViewById(R.id.image); | |
image.setTranslationX(-position * (pageWidth / 2)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment