【问题标题】:Android push view upAndroid 向上推视图
【发布时间】:2015-09-23 07:11:42
【问题描述】:

在我的 android 应用程序中,我有一个登录页面,当键盘打开时,我需要将整个视图向上推,现在发生的事情是……我有两个 edittext 一个用于用户名,另一个用于密码,下面两个 textview 用于忘记密码和新用户所以当我点击用户名edittext键盘打开并隐藏密码edittext和textviews时,我需要的是键盘需要推动整个视图..所以用户不需要按下后退按钮来隐藏键盘密码编辑文本..

我尝试过的... 我给了

android:windowSoftInputMode="stateVisible|adjustResize|adjustPan"

在 android manifest 中的活动和

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

在oncreate中,但它仍然隐藏了edittext和textviews...如果有人知道如何克服这种情况,请帮助

我的 xml 在下面给出

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:id="@+id/logo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:background="@color/red">
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/contentDescriptionContent"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp"
            android:src="@mipmap/logo" />
    </LinearLayout>
    <LinearLayout
        android:id="@+id/loginNow"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/logo"
        android:gravity="center"
        android:background="@drawable/main_header_selector">
        <TextView
            android:id="@+id/textViewAboutUs"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp"
            android:text="LOGIN NOW"
            android:textColor="@color/red"
            android:shadowColor="#FFFFFF"
            android:shadowDx="1"
            android:shadowDy="1"
            android:shadowRadius="2"
            android:textSize="18sp"
            android:textStyle="bold" />
    </LinearLayout>
    <ScrollView
        android:id="@+id/sView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/loginNow">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="2dp">

            <EditText
                android:id="@+id/editTextUserName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Mobile Number"
                android:inputType="number"
                android:maxLines="1"
                android:padding="10dp"
                android:background="@drawable/rect_text_edittext"
                android:layout_marginLeft="50dp"
                android:layout_marginRight="50dp"
                android:layout_marginTop="75dp"/>



            <EditText
                android:id="@+id/editTextPassword"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/password"
                android:inputType="textPassword"
                android:maxLines="1"
                android:padding="10dp"
                android:background="@drawable/rect_text_edittext"
                android:layout_below="@+id/editTextUserName"
                android:layout_marginLeft="50dp"
                android:layout_marginRight="50dp"
                android:layout_marginTop="3dp"/>

            <Button
                android:id="@+id/login_Button"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="50dp"
                android:layout_marginRight="50dp"
                android:layout_below="@+id/editTextPassword"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="20dp"
                android:layout_marginBottom="20dp"
                android:shadowColor="#000000"
                android:shadowDx="1"
                android:shadowDy="1"
                android:shadowRadius="2"
                android:gravity="center"
                android:minHeight="30dp"
                android:textColor="#ffffff"
                android:background="@drawable/custom_button"
                android:text="@string/login" />

            <TextView
                android:id="@+id/textViewIfNewUser"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/login_Button"
                android:layout_marginTop="8dp"
                android:layout_marginLeft="55dp"
                android:layout_alignParentLeft="true"
                android:text="@string/ifnewuser"
                android:textColor="#000000"
                android:textStyle="italic|bold"/>

            <TextView
                android:id="@+id/textViewNewUser"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/textViewIfNewUser"
                android:layout_alignBaseline="@+id/textViewIfNewUser"
                android:layout_marginLeft="8dp"
                android:text="@string/newuser"
                android:textColor="@drawable/text_color_red"
                android:textStyle="italic|bold"/>

            <TextView
                android:id="@+id/textViewIfForgotPassword"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/textViewIfNewUser"
                android:layout_marginTop="8dp"
                android:layout_marginLeft="55dp"
                android:layout_alignParentLeft="true"
                android:text="@string/ifforgotpassword"
                android:textColor="#000000"
                android:textStyle="italic|bold"/>

            <TextView
                android:id="@+id/textViewForgotPassword"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/textViewIfForgotPassword"
                android:layout_alignBaseline="@+id/textViewIfForgotPassword"
                android:layout_marginLeft="8dp"
                android:text="@string/forgotpassword"
                android:textColor="@drawable/text_color_red"
                android:textStyle="italic|bold"/>

        </RelativeLayout>
    </ScrollView>
</RelativeLayout>

【问题讨论】:

    标签: android xml view push android-softkeyboard


    【解决方案1】:

    在您的 AndroidManifest 中尝试将您的活动标签中的 softInputMode 值调整为仅“adjustResize”

    例如

    <activity
     android:name="YourActivity"
                android:windowSoftInputMode="adjustResize">
    </activity>
    

    我认为问题可能是因为您还有其他可用选项,因为“adjustPan”选项允许您的键盘停留在布局之上

    【讨论】:

    • 不..我检查了..它不工作..我应该问..我们需要让我们的父视图滚动视图..我的父视图是相对布局
    • 不,您不必将所有内容都包装在滚动视图中,因为该标志可以处理该问题。自从您在清单中进行更改后,您是否尝试过注释掉放置在 onCreate 中的“getWindow..”函数?
    【解决方案2】:

    你试过这个吗:

     android:windowSoftInputMode="adjustResize"
    

    【讨论】:

      猜你喜欢
      • 2016-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多