简体   繁体   中英

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM