Saqib February 2016

Android fixed background image in scrollview while scrolling

I have a situation where I need a scrollview to have a background image that shouldn't scroll along with it's parent when moving. Before any of you suggest me the links for setting background image and this that, I have already tried and it's not working.

The whole story goes like: I have an activity with fragments which have their own backgrounds with some input fields. When focusing over input fields, keyboard appears and background image squeezes. For that I put an image on background of scrollview that fixed my issue of squeezing background but raised another concern that background Image should stay static while scrolling the parent scrollview.

The second solution any of you may suggest is setting background of my activity rather playing with scrollview. That's right, but for that I had to make a style element with background of theme which appears odd while transitioning different fragments plus it adds overhead when I have a lot of code and fragments to move forward and back.

That's the point where I am stuck. I have gone through links below, if you just need to know that I tried it or not.

link1 link2 link3 ... and so on

below is the layout I am using for my fragments (it's all being done programmatically)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/top_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="ma        

Answers


Stanojkovic February 2016

Add someimgage to your drawable folderes, like drawable-mdpi, drawable-hdpi. In your LinearLayout "@+id/top_layout" add attribute:

android:background="@drawable/someimage"


LuXoR February 2016

If I guess right you try to fix your hotfix to get it working propperly. If I'm right you sould go back to scratch and do it without your scrollview.

If you have a look at following Link: http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

you'll see softkeyboard mode can be adjusted. "adjustPan" should solve your problem.

"adjustPan"

The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.


androidnoobdev February 2016

None of the above works for me with some reason but this things works.

getWindow().setBackgroundDrawableResource(R.mipmap.img_reg_bg);

put it in oncreate method hope it will help.

Post Status

Asked in February 2016
Viewed 2,383 times
Voted 7
Answered 3 times

Search




Leave an answer