0

I have a parent layout with background image, so after adding scroll view when the keyboard pops up the background image gets shrink.

Like below images :

enter image description here

enter image description here

I checked all solutions on SO, adding windowSofInput as adjustResize and adjustPan but adjustResize dosent solve the problem and by using adjustPan cant scroll up the page, scroll view dosent work with adjust pan.

I tried adding some attributes of scroll view like fillViewPort, adjustViewBounds to true.

Also I tried the true With this scroll view dose not shrink but, I dont need the full screen, status bar cant be seen with full screen.

I tried to add the image view rather than setting the background image to the parent layout, and tried to set its scaleType, matrix scale type dosent shrink but my backgroung image dose not look like original image.

It looks like tihs :

enter image description here

enter image description here

layout file

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    tools:context="com.example.admin.SmartCabFuelCard.RegisterDriver">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="matrix"
        android:src="@drawable/page"/>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/bg_color"
        android:alpha="0.5"/>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds = "true"
        android:isScrollContainer="true"
        android:fillViewport="true">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:context="com.example.admin.SmartCabFuelCard.RegisterDriver"><!--

  <ImageView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:src="@drawable/page"
      android:scaleType="fitXY"/>
-->


        <RelativeLayout
            android:id="@+id/rl"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerHorizontal="true"
            android:layout_marginEnd="@dimen/dimen_10dp"
            android:layout_marginStart="@dimen/dimen_10dp"
            android:layout_marginLeft="@dimen/dimen_10dp"
            android:layout_marginRight="@dimen/dimen_10dp">

            <ImageView
                android:id="@+id/logo"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="@dimen/dimen_20dp"
                android:src="@drawable/petrolpump" />

            <TextView
                android:id="@+id/register_driver_welcome"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_below="@+id/logo"
                android:layout_marginTop="@dimen/dimen_15dp"
                android:padding="@dimen/dimen_10dp"
                android:text="@string/welcome_driver"
                android:textColor="@color/divider_color"
                android:textStyle="bold" />

            <EditText
                android:id="@+id/edt_mobile"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/register_driver_welcome"
                android:drawableLeft="@drawable/ic_local_phone"
                android:hint="Mobile No."
                android:inputType="number"
                android:maxLength="10"
                android:maxLines="1"
                android:padding="@dimen/dimen_15dp"
                android:textColor="@color/divider_color"
                android:textColorHint="@color/hint_color"
                android:textSize="@dimen/dimen_15dp" />

            <TextView
                android:id="@+id/register_driver_enter"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_below="@+id/edt_mobile"
                android:padding="@dimen/dimen_10dp"
                android:text="@string/otp_send"
                android:textColor="@color/divider_color"
                android:textStyle="bold" />

            <EditText
                android:id="@+id/register_driver_otp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/register_driver_enter"
                android:layout_centerHorizontal="true"
                android:layout_gravity="center"
                android:layout_marginTop="@dimen/dimen_5dp"
                android:drawableLeft="@drawable/ic_lock_close"
                android:hint="OTP"
                android:inputType="number"
                android:maxLength="4"
                android:maxLines="1"
                android:padding="@dimen/dimen_15dp"
                android:textColor="@color/divider_color"
                android:textColorHint="@color/hint_color"
                android:textSize="@dimen/dimen_15dp" />


            <Button
                android:id="@+id/register_driver_register"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/register_driver_otp"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="@dimen/dimen_20dp"
                android:layout_marginTop="20dp"
                android:background="@color/colorPrimary"
                android:text="Register"
                android:textColor="@android:color/white" />

            <Button
                android:id="@+id/register_driver_sendotp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/edt_mobile"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="@dimen/dimen_40dp"
                android:layout_marginTop="20dp"
                android:background="@color/colorPrimary"
                android:text="Send OTP"
                android:textColor="@android:color/white" />

            <Button
                android:id="@+id/btn_resend"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignStart="@+id/register_driver_register"
                android:layout_below="@+id/register_driver_otp"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="@dimen/dimen_20dp"
                android:layout_marginTop="20dp"
                android:background="@color/colorPrimary"
                android:text="RESEND OTP"
                android:textColor="@android:color/white"
                android:visibility="gone" />
        </RelativeLayout>
    </RelativeLayout>
    </ScrollView>
</RelativeLayout>

Can anyone help me with this please? Thank you.

Sid
  • 2,792
  • 9
  • 55
  • 111
  • Please post your layout xml – Naz141 Nov 30 '17 at 07:11
  • yes added please check @Naz141 – Sid Nov 30 '17 at 07:29
  • maybe this helps: https://stackoverflow.com/questions/16135984/full-screen-background-image-in-an-activity (using frame layout and add the image view first) .. also is there a reason why u nest your relative layout inside another relative layout (scroll view -> relative layout -> relative layout)? – Jason Saruulo Nov 30 '17 at 07:39
  • yes,, but this not helping it still gets shrink. @JasonSaruulo – Sid Nov 30 '17 at 08:03

2 Answers2

0

Don't set the background in xml. Set the image as window background in your activity as.

getWindow().setBackgroundDrawableResource(R.drawable.bg);

And manifest entry

<activity
        android:name=".ActivityName"
        android:configChanges="screenSize|keyboard|orientation|screenSize"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar"
        android:windowSoftInputMode="stateHidden" />
ADM
  • 20,406
  • 11
  • 52
  • 83
  • This is working.. but some image hides below appbar as it is set to the window screen. @ADM – Sid Nov 30 '17 at 07:41
  • Yeah thats because its sets to window . If you are using AppBar then you can just use Linearlayout in xml as root with android:windowSoftInputMode="adjustNothing" in manifest. I sent this solution because the images you attached don't show any AppBar . – ADM Nov 30 '17 at 07:47
  • I cant use Linear layout, I have alredy set the view according to relative layout as parent. I tried to add adjustNothing to relative but did not work. – Sid Nov 30 '17 at 07:58
  • Your layout doesn't seems complex its so simple . if putting Linear layout solve issue so just add it as root parent layout . – ADM Nov 30 '17 at 08:17
  • ok I tried but it did not solve the issue, image is still behind the app bar. – Sid Nov 30 '17 at 09:26
  • Update your xml in question . cause don't see any AppBar right now. – ADM Nov 30 '17 at 09:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/160176/discussion-between-sid-and-adm). – Sid Nov 30 '17 at 09:38
-1

If you want to set a background image, you should set it on your parent relativelayout instead of using an imageview.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/page"
tools:context="com.example.admin.SmartCabFuelCard.RegisterDriver">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/bg_color"
    android:alpha="0.5"/>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:adjustViewBounds = "true"
    android:isScrollContainer="true"
    android:fillViewport="true">

.....
Joshua
  • 589
  • 1
  • 5
  • 19