ImageView作为背景被打开键盘推高

时间:2017-09-14 10:47:13

标签: android background imageview relativelayout

由于我使用png作为我的视图的背景,我不希望它以一种奇怪的方式伸展。所以我将一个ImageView放在RelativeLayout中,并将其参数设置为匹配parent。

当我点击edittext并且键盘正在打开时,会出现问题。 android:windowSoftInputMode="adjustResize"和键盘将相对布局内的每个视图都推到一起,因此我的背景图像会移动到。你知道怎么解决这个问题吗?

基本上我想调整视图而不是背景图像。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/login_relative"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:hapticFeedbackEnabled="false"
    tools:context="com.example.radzik.recipes.activity.LoginActivity">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:adjustViewBounds="false"
    android:cropToPadding="false"
    android:scaleType="centerCrop"
    app:srcCompat="@drawable/background_activity_login" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="50dp"
    android:gravity="center_horizontal">

    <ProgressBar
        android:id="@+id/progress_bar_login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="8dp"
        android:visibility="gone" />

    <LinearLayout
        android:id="@+id/login_details"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_toEndOf="@+id/progress_bar_login"
        android:orientation="vertical">

        <TextView
            android:id="@+id/text_view_email_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="54dp"
            android:layout_marginTop="15dp"
            android:elevation="0dp"
            android:fontFamily="@string/roboto_thin_typeface_asset_path"
            android:text="EMAIL"
            android:textColor="@color/white_transparent"
            android:textSize="12sp" />

        <EditText
            android:id="@+id/edit_text_email_id"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="50dp"
            android:layout_marginRight="50dp"
            android:backgroundTint="@android:color/transparent"
            android:fontFamily="@string/roboto_condensed_typeface_asset_path"
            android:hint="example@gmail.com"
            android:inputType="textEmailAddress"
            android:textColor="@android:color/white"
            android:textColorHint="@android:color/white" />


        <TextView
            android:id="@+id/text_view_password"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="54dp"
            android:layout_marginTop="15dp"
            android:elevation="0dp"
            android:fontFamily="@string/roboto_thin_typeface_asset_path"
            android:text="PASSWORD"
            android:textColor="@color/white_transparent"
            android:textSize="12sp" />

        <EditText
            android:id="@+id/edit_text_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/text_view_password"
            android:layout_marginLeft="50dp"
            android:layout_marginRight="50dp"
            android:backgroundTint="@android:color/transparent"
            android:fontFamily="@string/roboto_condensed_typeface_asset_path"
            android:inputType="textPassword"
            android:paddingBottom="5dp"
            android:paddingTop="0dp"
            android:textColor="@android:color/white"
            android:textColorHint="@android:color/white"
            android:textSize="30sp" />


        <Space
            android:layout_width="1dp"
            android:layout_height="20dp" />


        <Button
            android:id="@+id/button_sign_in"
            style="?android:textAppearanceSmall"
            android:layout_width="350dp"
            android:layout_height="50dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/button_sign_in"
            android:onClick="onLoginClicked"
            android:padding="10dp"
            android:text="Log In"
            android:textColor="@android:color/white"
            android:textStyle="bold" />

        <Space
            android:layout_width="1dp"
            android:layout_height="35dp" />

        <!--<Button-->
        <!--android:id="@+id/button_facebook_sign_in"-->
        <!--style="?android:textAppearanceSmall"-->
        <!--android:layout_width="fill_parent"-->
        <!--android:layout_height="fill_parent"-->
        <!--android:background="@color/colorPrimaryDark"-->
        <!--android:onClick="onFacebookLogInClicked"-->
        <!--android:padding="10dp"-->
        <!--android:layout_marginLeft="10dp"-->
        <!--android:layout_marginRight="10dp"-->
        <!--android:text="Login with Facebook"-->
        <!--android:textStyle="bold"-->
        <!--android:textColor="@color/colorText"/>-->

        <com.facebook.login.widget.LoginButton
            android:id="@+id/button_facebook_login"
            android:layout_width="350dp"
            android:layout_height="50dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:textStyle="bold"
            />

       <!--  <Button
            android:id="@+id/button_facebook_login"
            android:layout_width="350dp"
            android:layout_height="50dp"
            android:layout_centerInParent="true"
            android:layout_gravity="center_horizontal"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/button_facebook_log_in"
            android:drawableLeft="@drawable/facebook_white_logo_custom_1"
            android:paddingLeft="10dp"
            android:paddingRight="36dp"
            android:text="Facebook"
            android:textColor="@android:color/white"
            android:textStyle="bold" /> -->

        <Space
            android:layout_width="1dp"
            android:layout_height="10dp" />


        <ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dp"
            app:srcCompat="@drawable/login_bottom_coloured_line" />

        <Button
            android:id="@+id/button_sign_up"
            style="?android:textAppearanceSmall"
            android:layout_width="fill_parent"
            android:layout_height="60dp"
            android:background="#040C12"
            android:onClick="onSignUpClicked"
            android:padding="10dp"
            android:text="SIGN UP"
            android:textColor="@android:color/white"
            android:textStyle="bold" />

    </LinearLayout>

</RelativeLayout>

背景图片: background image

2 个答案:

答案 0 :(得分:0)

试试这个:

将ImageView放在scrollview中。

  <ScrollView
    android:id="@+id/scrollView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:src="@drawable/background_activity_login"/>
</ScrollView>

在java set中,scrollview在onCreate方法中启用了false,如下所示:

ScrollView scrollView = (ScrollView)findViewById(R.id.scrollView);
scrollView.setEnabled(false);

答案 1 :(得分:0)

只需写入xml

即可
<script>
    function actionApi() {
        setTimeout(
                function() {
                    var node = document.getElementsByClassName("raspuns")[document
                            .getElementsByClassName("raspuns").length - 1];
                    textContent = node.textContent;
                    document.getElementById("jsonResponse").innerHTML = textContent;
                    console.log(textContent);
                }, 1500);
    }
</script>