0

I need some help with an idea I had for an application I'm developing.
I have a main activity, which has a background image that is wider than the screen, and I wanted to make that image look and act like the android main screen
Android main screen
But I not being able to make the background ImageView to act like it. Here's my code:

MainActivity:

// slide effect in background
background = (ImageView) findViewById(R.id.imgBackMain);
backgroundAnim = new TranslateAnimation(TranslateAnimation.ABSOLUTE, 0f, TranslateAnimation.ABSOLUTE,
        100f, TranslateAnimation.ABSOLUTE, 0f, TranslateAnimation.ABSOLUTE, 0f);
backgroundAnim.setDuration(10000);
backgroundAnim.setRepeatCount(-1);
backgroundAnim.setRepeatMode(Animation.REVERSE);
backgroundAnim.setInterpolator(new LinearInterpolator());
background.setAnimation(backgroundAnim);

And here's my activity.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rlMain"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#088A08"
    tools:context="com.racsa.UI.MainActivity">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/imgBackMain"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:src="@mipmap/pantalla_principal"
        android:layout_alignParentStart="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/btnMain"
        android:onClick="goMaps"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/lblLoginPopUp"
        android:id="@+id/btnOpenLoginOptions"
        android:onClick="openLoginOptions"
        android:layout_marginBottom="15dp"
        android:textColor="#ffffff"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="@string/lblTurismo"
        android:id="@+id/lblTurismo"
        android:textColor="#ffffff"
        android:layout_marginBottom="15dp"
        android:layout_above="@+id/btnOpenLoginOptions"
        android:layout_centerHorizontal="true" />
</RelativeLayout>

This is how my activity looks like at the moment (I've been trying with the setScaleType method, don't blame me lol) Main activity

It doesn't matter if is done automatically or if I have to scroll myself, I just want to make it look and act like the android main screen background. I have also tried to put the image as a background for the Relative layout, with no success

Thanks in advance!

EDIT
After trying to add Sprockets to my project, I have an annoying Class not found error, in v4.view.ViewPager and I'm really starting to get nuts with this. This is my dependencies module in the projects' Gradle file:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:22.1.+'
    compile 'com.google.code.gson:gson:2.2.4'
    // Google Play Services
    compile 'com.google.android.gms:play-services:6.5.87'
    // Facebook
    compile 'com.facebook.android:facebook-android-sdk:4.0.1'
    compile 'net.sf.sprockets:sprockets-android:2.4.0'
}

How can I fix this?

pamobo0609
  • 812
  • 10
  • 21

1 Answers1

0

Something like this? Check out TranslateImagePageChangeListener, part of Sprockets (disclosure: I'm the developer).

pushbit
  • 1,268
  • 9
  • 14
  • I was doing fine working with Sprockets(looks really cool btw), and I got this error saying "java finished with non-zero exit value 2" and I'm not being able to test the app, did I miss something? – pamobo0609 May 15 '15 at 16:58
  • If you can reproduce that error and it's related to the library, create an issue on GitHub and I'll look into it. A screenshot would be nice as well, since I don't think I've seen that kind of error while working with an Android app and am not sure where it would appear. – pushbit May 15 '15 at 18:30
  • Thanks for the response. I actually fixed the error(my bad actually), now I'm struggling with some ViewPager recognition error, no biggie... I'll let you know when I'm actually into Sprockets – pamobo0609 May 15 '15 at 18:56
  • Hey dude! I haven't been able to get into sprockets. Android Studio just won't work with android support. I'm going to make a full reinstall to see whats up :( – pamobo0609 May 19 '15 at 18:54
  • Try removing `support-v4`, `gson`, and `play-services` from your `dependencies`. Sprockets already includes all of those. I've heard Android Studio/Gradle can get confused when dependencies are included multiple times. – pushbit May 19 '15 at 18:59
  • Removed them, no success. I think I'm going back to Eclispe to finish this project, Android studio in this particular case is not working properly – pamobo0609 May 19 '15 at 19:36
  • I'm in eclipse again. Is there a way to import Sprockets there? – pamobo0609 May 19 '15 at 20:45
  • If you aren't using a dependency management system like Maven or Gradle, then it wouldn't be easy to set up manually because there are many dependencies in the tree. If you only need `TranslateImagePageChangeListener`, you could just copy that class and `ObservableImageView` to your project. – pushbit May 20 '15 at 10:01
  • I gave up. I finished using a custom viewpager, in eclipse, with a pretty close approach to sprockets. Even though, I'm going to add it to my bookmarks to try it later. Great project! – pamobo0609 May 20 '15 at 16:27