代码之家  ›  专栏  ›  技术社区  ›  Pouria Hemi

打开键盘时如何调整xml的大小?

  •  0
  • Pouria Hemi  · 技术社区  · 6 年前

    linearLayout 选择“编辑文本”并打开键盘时

    我的xml代码:

    <android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".base.BaseAppCompatActivity"
    android:background="#868136d7"
    >
    
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >
            <com.airbnb.lottie.LottieAnimationView
                android:id="@+id/animation_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:lottie_fileName="splash.json"
                app:lottie_loop="true"
                app:lottie_autoPlay="true" />
        </LinearLayout>
    
    
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            >
    
            <android.support.v7.widget.Toolbar
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize">
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
    
                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_weight="0.2"
                        android:layout_height="match_parent">
                        <ImageView
                            android:id="@+id/convert_back"
                            android:layout_width="20dp"
                            android:layout_gravity="center"
                            android:layout_height="20dp"
                            android:src="@drawable/ic_back"
                            />
    
                    </LinearLayout>
    
    
                    <TextView
                        android:gravity="center"
                        android:layout_width="0dp"
                        android:layout_weight="0.8"
                        android:layout_height="match_parent"
                        android:textColor="@color/colorWhite"
                        android:text="@string/txt_toolbar_register_login"
                        android:textSize="14dp"
                        />
    
                    <TextView
                        android:gravity="center"
                        android:layout_width="0dp"
                        android:layout_weight="0.2"
                        android:layout_height="match_parent"
    
                        />
    
    
    
    
                </LinearLayout>
    
    
            </android.support.v7.widget.Toolbar>
    
            <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:gravity="center"
            android:layout_marginBottom="?attr/actionBarSize"
                android:orientation="vertical">
    
    
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/logo"
                    />
    
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/txt_register_login"
                    android:textColor="@color/colorWhite"
                    android:textSize="18dp"
                    />
    
    
                <EditText
                    android:inputType="number"
                    android:layout_width="match_parent"
                    android:layout_height="45dp"
                    android:background="@drawable/radius_edt"
                    android:layout_marginRight="60dp"
                    android:layout_marginLeft="60dp"
                    android:layout_marginTop="20dp"
                    android:id="@+id/phoneNumberEdt"
                    android:layout_marginBottom="25dp"
                    />
    
                <Button
                    android:id="@+id/btn_mobile_confirm"
                    android:layout_width="match_parent"
                    android:layout_height="45dp"
                    android:background="@drawable/radius_button"
                    android:layout_marginRight="60dp"
                    android:layout_marginLeft="60dp"
                    android:text="@string/register"
                    android:textColor="#ffffff"
                    />
    
            </LinearLayout>
    
    
    
        </LinearLayout>
    
    
    
    </RelativeLayout>
    

    图2是当选择编辑文本并打开键盘时 enter image description here enter image description here

    你认为这个问题有解决办法吗?如果有,怎么办?

    1 回复  |  直到 6 年前
        1
  •  2
  •   Chirag Savsani    6 年前

    添加 android:windowSoftInputMode="adjustResize" AndroidManifest.xml 为了你的活动。