【问题标题】:How to move whole layout move up when soft keyboard open in android在android中打开软键盘时如何向上移动整个布局
【发布时间】:2012-11-29 14:10:08
【问题描述】:

我想移动其中包含多个视图的布局,以便在用户触摸编辑文本时 然后键盘打开,我的布局小部件上升。 我什至在清单 android:windowSoftInputMode="adjustPan" 中使用了代码 然后 android:windowSoftInputMode="adjustPan|adjustResize" 没有任何效果,所以请帮助我
这是我的xml

   <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/theme_color"
        android:orientation="vertical" >

        <RelativeLayout
            android:id="@+id/relativeLAyoutId"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:focusable="true"
            android:focusableInTouchMode="true" >

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:src="@drawable/osmosis_label" />

            <EditText
                android:id="@+id/login_screen_username_editText1"
                android:layout_width="220dp"
                android:layout_height="40dp"
                android:layout_below="@+id/imageView1"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="15dp"
                android:ellipsize="start"
                android:ems="10"
                android:gravity="left"
                android:hint="@string/username_editbox_text"
                android:imeOptions="actionNext"
                android:singleLine="true" >

                <requestFocus />
            </EditText>

            <EditText
                android:id="@+id/login_screen_password_editText2"
                android:layout_width="220dp"
                android:layout_height="40dp"
                android:layout_alignLeft="@+id/login_screen_username_editText1"
                android:layout_below="@+id/login_screen_username_editText1"
                android:layout_marginTop="15dp"
                android:ellipsize="start"
                android:ems="10"
                android:gravity="left"
                android:hint="@string/password_editbox_text"
                android:imeOptions="actionDone"
                android:inputType="textPassword"
                android:textColor="@color/login_layout" >
            </EditText>

            <ImageView
                android:id="@+id/login_screen_submit_button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/login_screen_password_editText2"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="15dp"
                android:src="@drawable/log_in"
                android:text="Login" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/login_screen_submit_button1"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="15dp"
                android:text="@string/registered_textview_id"
                android:textColor="@color/grey_color"
                android:textSize="18sp"
                android:textStyle="bold" />
        </RelativeLayout>

    </RelativeLayout>

【问题讨论】:

标签: android android-layout


【解决方案1】:

把它放在你的 oncreate 中。

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-25
    • 2010-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多