Giter Club home page Giter Club logo

androidscrollingimageview's Introduction

Scrolling Image View

An Android view for displaying repeated continuous side scrolling images. This can be used to create a parallax animation effect.

Example

Example

Installation

Step 1. Add the JitPack repository to your project build.gradle file

allprojects {
    repositories {
        // ~~~
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency in the form

dependencies {
    implementation 'com.github.Q42:AndroidScrollingImageView:1.3.4'
}

Sample app

Please see the sample app for some examples

Sample App

Usage

In your Android layout file add:

<com.q42.android.scrollingimageview.ScrollingImageView
    android:id="@+id/scrolling_background"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    scrolling_image_view:speed="60dp"
    scrolling_image_view:contiguous="false"
    scrolling_image_view:source="@drawable/scrolling_background" />

There are three attributes for the ScrollingImageView:

  • speed is the number of dp's to move the drawable per second (may be a negative number)

  • source is the drawable to paint. May refer to an array of drawables

  • contiguous When source is an array of drawables, contiguous determines their ordering.

    false (default) for random ordering, true for the same order as in the array

Don't forget to add the namespace to your root XML element

xmlns:scrolling_image_view="http://schemas.android.com/apk/res-auto"

In your Java code, you can start and stop the animation like this:

ScrollingImageView scrollingBackground = (ScrollingImageView) loader.findViewById(R.id.scrolling_background);
scrollingBackground.stop();
scrollingBackground.start();

Parallax effect

In order to achieve a parallax effect, you can stack multiple ScrollingImageView's in a FrameLayout with different speeds. For example:

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

  <com.q42.android.scrollingimageview.ScrollingImageView
      android:id="@+id/scrolling_background"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      scrolling_image_view:speed="60dp"
      scrolling_image_view:source="@drawable/scrolling_background" />
      
  <com.q42.android.scrollingimageview.ScrollingImageView
      android:id="@+id/scrolling_foreground"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      scrolling_image_view:speed="150dp"
      scrolling_image_view:source="@drawable/scrolling_foreground" />
</FrameLayout>

androidscrollingimageview's People

Contributors

gerpanobanano avatar long1eu avatar ninovanhooff avatar shaunidiot avatar tsuijten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

androidscrollingimageview's Issues

gradle failed

Error:Execution failed for task ':app:processDebugManifest'.

Manifest merger failed : uses-sdk:minSdkVersion 14 cannot be smaller than version 16 declared in library [com.github.Q42:AndroidScrollingImageView:1.1] /home/om/AndroidStudioProjects/GoRide/app/build/intermediates/exploded-aar/com.github.Q42/AndroidScrollingImageView/1.1/AndroidManifest.xml
Suggestion: use tools:overrideLibrary="com.q42.android.scrollingimageview" to force usage

Add support for scaleType as on ImageView

It would be much nicer to be able to adjust this custom view's height to its parent, right now with match_parent your image will just be bigger than your parent component.

An ImageView already has scaleType to solve this issue.

So maybe you could inherit your component from ImageView or build something alike?

Android 7 crash version 1.2

 Caused by: java.lang.NullPointerException: Attempt to read from field 'int android.util.TypedValue.type' on a null object reference
        at com.q42.android.scrollingimageview.ScrollingImageView.<init>(ScrollingImageView.java:83)
        at java.lang.reflect.Constructor.newInstance0(Native Method) 
        at java.lang.reflect.Constructor.newInstance(Constructor.java:430) 
        at android.view.LayoutInflater.createView(LayoutInflater.java:645) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:858) 
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:518) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426) 
        at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:126) 
        at androidx.databinding.ViewDataBinding.inflateInternal(ViewDataBinding.java:1409) 

Caused by: java.lang.OutOfMemoryError: Failed to allocate a 29160012 byte allocation with 4194304 free bytes and 24MB until OOM
        at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
        at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
        at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:620)
        at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:455)
        at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:478)
        at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:508)
        at com.q42.android.scrollingimageview.ScrollingImageView.<init>(ScrollingImageView.java:82)
        at java.lang.reflect.Constructor.newInstance0(Native Method) 
        at java.lang.reflect.Constructor.newInstance(Constructor.java:430) 
        at android.view.LayoutInflater.createView(LayoutInflater.java:645) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:858) 
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:861) 
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:861) 
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:518) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426) 
        at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:126) 
        at androidx.databinding.ViewDataBinding.inflateInternal(ViewDataBinding.java:1409) 
        at com.fwd.codigo.databinding.FragmentStartBinding.inflate(FragmentStartBinding.java:109) 
        at com.fwd.codigo.databinding.FragmentStartBinding.inflate(FragmentStartBinding.java:95) 
        at com.fwd.codigo.feature.onboarding.StartFragment.onCreateView(StartFragment.kt:70) 
        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2950) 
        at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:515) 
        at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282) 
        at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2177) 
        at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2088) 
        at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1990) 
        at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:524) 
        at android.os.Handler.handleCallback(Handler.java:751) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6077) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 
2022-07-21 12:16:19.716 13336-13402/com.fwd.codigo.dev E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
2022-07-21 12:16:19.717 13336-13402/com.fwd.codigo.dev E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824

Enter + exit

Is it possible to create the same type of animation for entering and exiting the ImageView, like in the preview GIF?:

preview

The following classes could not be instantiated

While editing my layout in Android Studio 2.2 Build #AI-145.3276617 I get this error right after including ScrollingImageView

The following classes could not be instantiated

java.lang.NullPointerException
	at com.q42.android.scrollingimageview.ScrollingImageView.<init>(ScrollingImageView.java:47)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:465)
	at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:172)
	at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:105)
	at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:186)
	at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:334)
	at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:345)
	at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:245)
	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
	at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858)
	at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
	at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)
	at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
	at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:861)
	at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
	at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)
	at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
	at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
	at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
	at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:324)
	at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429)
	at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:389)
	at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:548)
	at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:533)
	at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:966)
	at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:533)
	at com.android.tools.idea.rendering.RenderTask.lambda$inflate$72(RenderTask.java:659)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

As of now I'm trying to debug the problem by myself but it seems I can't get a solution. But if I get one I'll post here

Little bit stuck

I love this lib.

but one issue what I marked that.

When I change activity it little bit stuck scrolling and after then activity change.

How to scroll perfectly diagonally??

while (offset <= -getBitmap(arrayIndex).getHeight()) {
offset += getBitmap(arrayIndex).getHeight();
arrayIndex = (arrayIndex + 1) % scene.length;
}

        float start = offset;
        for (int i = 0; start < clipBounds.height(); i++) {
            Bitmap bitmap = getBitmap((arrayIndex + i) % scene.length);
            int width = bitmap.getWidth();
            int height = bitmap.getHeight();
            canvas.drawBitmap(bitmap, getBitmapLeft(width, start), getBitmapTop(height, start), null);
            start += width;
        }

        if (isStarted && speed != 0) {
            offset -= abs(speed);
            postInvalidateOnAnimation();
        }

Failed to resolve: com.github.Q42:AndroidScrollingImageView:1.3.3

under project model (build.gradle)
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}

under app model (build.gradle)
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.github.Q42:AndroidScrollingImageView:1.3.3'
}

Failed to resolve: com.github.Q42:AndroidScrollingImageView:1.3.2 error

I'm using android studio 3.1.2, my app gradle is given below:

apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.ajay.pocketassistance"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
implementation 'com.andkulikov:transitionseverywhere:1.7.4'
implementation 'com.github.bumptech.glide:glide:4.7.1'
implementation 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:2.1.0'
implementation 'com.github.Q42:AndroidScrollingImageView:1.3.2'
}

Is it a bug?

set offset yourself

if you were to set the scrolling offset yourself instead of setting a speed variable, how would you do it?

Failed to resolve.

ive added the implementation 'com.github.Q42:AndroidScrollingImageView:1.3.2' line in dependencies in build.gradle ( Module: app ). im getting this error

Error inflating class scrollingimageview Android 4.0.4

11-16 13:26:05.080: E/AndroidRuntime(3447): java.lang.RuntimeException: Unable to start activity ComponentInfo{scrollingimageview.android.q42.com.sampleapp/scrollingimageview.android.q42.com.sampleapp.MainActivity}: android.view.InflateException: Binary XML file line #28: Error inflating class scrollingimageview.android.q42.com.sampleapp.ScrollingImageView

Getting null pointer exception

Caused by: java.lang.NullPointerException: Attempt to read from field 'int android.util.TypedValue.type' on a null object reference
at com.q42.android.scrollingimageview.ScrollingImageView.(ScrollingImageView.java:57)

How to use in Android Studio

Step 1. Add the JitPack repository to your build file

repositories {
// ...
maven { url "https://jitpack.io" }
}
Step 2. Add the dependency in the form

dependencies {
compile 'com.github.Q42:AndroidScrollingImageView:1.0'
}

I can not understand how to use

Is it possible to make it fullscreen?

HI , thank you for your beautiful work.
I am wondering if it is possible to stretch the image to full screen, i have tried to set the width and height to match parent but it stays the same and doesn't stretch. it does stretch in width but not in height :/
what should it do?

How to display images in order?

How do I specify the sequence of images?
If one ,It prompts “Bitmap too large to be uploaded into a texture (7333x479, max=4096x4096)” , So I cut a picture into pieces so that can show it .

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.