Arun
Arun

Reputation: 1668

scrolling the background image in android java while adding a view to screen

I want to scroll the background in android. I have a scrollview which has many views. I need to implement a way wherein i need to scroll only the background while adding the views. I came across many forums but none of them are very clear. Please give an idea or references to implement it. To give more idea for what i am looking for is, Just consider a bike game wherein the background road image moves while riding the bike. I just need similar implementation while scrolling the screen.

Upvotes: 1

Views: 745

Answers (1)

Comic Sans MS Lover
Comic Sans MS Lover

Reputation: 1729

Maybe you could do like this:

  • RelativeLayout as the parent
    • ScrollView with your image set as background
  • Then the other views, but outside of the ScrollView and inside of the RelativeLayout.

EDIT:

<RelativeLayout
 android:id="@+id/relParent"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 >

 <OtherViews />

 <ScrollView
  android:id="@+id/scrlParent"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" 
  android:background="@drawable/yourbackground">

  </ScrollView>     

 </RelativeLayout>

I think that something like this might work. You see, the RelativeLayout is the parent. Then comes your other views, on the top of your ScrollView. Then, after your other views tag, comes the ScrollView, with only a background. I'm not sure if a background tag would work, so maybe you should remove the android:background="@drawable/yourbackground" and put an ImageView inside of the ScrollView.

Upvotes: 2

Related Questions