背景图像在键盘弹出上缩小

时间:2017-11-30 07:08:15

标签: android image scrollview drawable window-soft-input-mode

我有一个带有背景图像的父布局,所以在键盘弹出后添加滚动视图后,背景图像会缩小。

如下图所示:

enter image description here

enter image description here

我在SO上检查了所有解决方案,将windowSofInput添加为adjustResize和adjustPan但adjustResize dosent解决了问题,并使用adjustPan cant向上滚动页面,滚动视图dosent与adjust pan一起工​​作。

我尝试添加滚动视图的一些属性,如fillViewPort,adjustViewBounds为true。

我也试过了     真正 这个滚动视图不会缩小,但我不需要全屏,状态栏不能全屏显示。

我尝试添加图像视图而不是将背景图像设置为父版面,并尝试设置其scaleType,矩阵比例类型剂量缩小但我的背景图像看起来不像原始图像。

看起来像是:

enter image description here

enter image description here

布局文件

<?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>

有人可以帮我吗?谢谢。

2 个答案:

答案 0 :(得分:0)

不要在xml中设置背景。在活动中将图像设置为窗口背景。

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

并显示条目

<activity
        android:name=".ActivityName"
        android:configChanges="screenSize|keyboard|orientation|screenSize"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar"
        android:windowSoftInputMode="stateHidden" />

答案 1 :(得分:-1)

如果要设置背景图像,则应在父亲相对布局上设置,而不是使用图像视图。

<?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">

.....