即使在adjustPan,adjustResize

时间:2017-05-17 07:09:22

标签: android android-layout

我的代码如下所示:

的AndroidManifest.xml

<activity
        android:name=".activity.LogInActivity"
        android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:screenOrientation="landscape"
        android:windowSoftInputMode="stateHidden|adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

activity_login.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="@drawable/ic_dashback"
   >


    <RelativeLayout
        android:id="@+id/card_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_gravity="center"
        >

        <RelativeLayout
            android:layout_width="235dp"
            android:layout_height="264dp"
            android:background="@color/colorMobster7B"
            android:fitsSystemWindows="true"
            android:orientation="vertical"
            android:paddingLeft="20dp"
            android:paddingRight="20dp">


            <EditText
                android:id="@+id/userName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="40dp"
                android:background="@drawable/background_edittext_login"
                android:hint="Email"
                android:maxLines="1"
                android:minLines="1"
                android:paddingBottom="5dp"
                android:singleLine="true"
                android:textColor="@color/colorBlackCurrent"
                android:textColorHint="@color/colorBlackCurrent"
                android:textSize="13sp" />


            <EditText
                android:id="@+id/password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/userName"
                android:layout_marginTop="20dp"
                android:background="@drawable/background_edittext_login"
                android:hint="Password"
                android:inputType="textPassword"
                android:maxLines="1"
                android:minLines="1"
                android:paddingBottom="5dp"
                android:singleLine="true"
                android:textColor="@color/colorBlackCurrent"
                android:textColorHint="@color/colorBlackCurrent"
                android:textSize="13sp" />


            <TextView
                android:id="@+id/forgotPassword"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/password"
                android:layout_marginTop="13dp"
                android:text="Forgot Password"
                android:textSize="13sp" />


            <Button
                android:id="@+id/loginButton"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_below="@+id/forgotPassword"
                android:layout_marginBottom="10dp"
                android:layout_marginTop="27dp"
                android:background="@color/colorBlackCurrent"
                android:gravity="center_vertical|center"
                android:text="LOGIN"
                android:textAllCaps="true"
                android:textColor="@color/colorMobster7B"
                android:textSize="17sp" />

            <TextView
                android:id="@+id/createAccount"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/loginButton"
                android:layout_gravity="center"
                android:text="Create account"
                android:textAllCaps="true"
                android:textSize="17sp" />
        </RelativeLayout>

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/card_view"
        android:layout_centerInParent="true"
        android:layout_marginTop="18dp"
        android:gravity="center_vertical">

        <TextView
            android:id="@+id/bottomText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Powered by"
            android:textAllCaps="true"
            android:textColor="@color/colorMobster7B"
            android:textSize="12sp" />

        <ImageView
            android:layout_width="55dp"
            android:layout_height="19dp"
            android:layout_marginLeft="10dp"
            android:layout_toRightOf="@+id/bottomText"
            android:background="@drawable/ic_quflip" />
    </RelativeLayout>

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="105dp"
        android:visibility="invisible" />


</RelativeLayout>

LoginActivity.java

public class LogInActivity extends AppCompatActivity {
.....
 @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
.....
}
}

现在,我的布局是平板电脑。我想要的是,一旦键盘打开,整个布局应该向上移动,而不是特定的edittexts区域。 我已经尝试了&#34; adjustPan&#34;,&#34; adjustResize&#34;,&#34; adjustPan | adjustResize&#34;我已经将每个布局定义为relativelayout。但没有任何作用,那么我该怎么做才能使它发挥作用呢?

1 个答案:

答案 0 :(得分:1)

Manifest内定义android:windowSoftInputMode,如下所示。

android:windowSoftInputMode="stateHidden|adjustResize"

Activity programmatically内也可以这样做。

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

修改

同样在Manifest内添加,然后尝试。

android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"

我已使用layout测试了输出。

下面是平板电脑输出。

enter image description here