当键盘变得可见时,使按钮保持可见

时间:2016-07-07 12:23:34

标签: android keyboard resize ime

我有下一个布局

enter image description here

当键盘出现时,我不希望布局的绿色标记部分始终可见。另外一个词我需要看到EditText和Button。

这是我的代码草图:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="16dp"
tools:context="com.mynfo.concept.auth.AuthActivity">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/titleImageView"
    android:layout_gravity="center"
    android:src="@drawable/title_auth"
    android:layout_weight="0"
    android:layout_marginTop="48dp"
    android:layout_marginBottom="48dp"
    />

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0"
    android:layout_marginBottom="8dp"
    android:focusable="true"
    android:focusableInTouchMode="true"
    >

    <EditText
        android:id="@+id/barcode_editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:inputType="number"
        android:textColorHint="@color/darker_grey"
        android:hint="edittext"
        android:maxLength="15"
        android:ellipsize="end"
        android:ems="10"
        android:background="#0000"
        android:layout_gravity="left|center_vertical"/>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/ic_menu_camera"
        android:layout_gravity="right|center_vertical"/>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/grey"
        android:layout_gravity="bottom"/>

</FrameLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_weight="1">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <com.melnykov.fab.FloatingActionButton
            android:id="@+id/button_scan"
            android:layout_width="64dp"
            android:layout_height="64dp"
            fab:fab_colorNormal=    "@color/turquoise"
            fab:fab_colorPressed=   "@color/turquoise_black"
            fab:fab_colorRipple=    "@color/turquoise_light"
            android:src="@android:drawable/ic_menu_camera"
            android:layout_gravity="center"/>
    </FrameLayout>

    <Button
        android:id="@+id/button_link_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Authorize"
        android:background="@drawable/button_authorize_selector"
        android:enabled="false"
        android:layout_weight="0"
        />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1.2">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_gravity="center"
            android:gravity="center">

            <TextView
                style="@style/TextViewPrimary"
                android:layout_marginLeft="32dp"
                android:layout_marginRight="32dp"
                android:textSize="16sp"
                android:text="Enter your name"
                android:gravity="center" />

            <com.mynfo.concept.views.FontFitTextView
                style="@style/TextViewSecondary"
                android:text="And then you will got the access"
                android:gravity="center" />

        </LinearLayout>


        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/authenticatingView"
            android:background="#fff">

            <ProgressBar
                style="?android:attr/progressBarStyleLarge"
                android:indeterminateOnly="true"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/authenticatingProgressBar"
                android:layout_gravity="center"/>

        </FrameLayout>

    </FrameLayout>




</LinearLayout>

什么没有用:adjustPan,adjustSize有或没有布局权重。

也许我做错了什么?

感谢您的进一步帮助。

P.S。我知道这段代码感觉多余,但有一些目的,如屏幕适应。

1 个答案:

答案 0 :(得分:0)

在您的代码中的AndroidMenifest.xml文件中使用

windowsSoftInputMode = "adjustResize"

或者在ScrollView中采用整个布局

windowsSoftInputMode = "adjustPan"

示例代码段:

        <activity
            android:name=".activityname"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustPan|adjustResize" >

        </activity>

使用 ScrollView中的android:fillViewport="true"标记。为了避免布局大小错误,请在Top ScrollView中使用margin并且不要在ScrollView子项中使用它。

并在OnCreate中添加

    scrollView = (ScrollView) this.findViewById(R.id.scrollView);
    scrollView.setVerticalScrollBarEnabled(false);
    imageView = (ImageView) findViewById(R.id.imageView);

    this.findViewById(android.R.id.content).addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
            scrollView.scrollTo(0, imageView.getHeight() + ((ViewGroup.MarginLayoutParams) imageView.getLayoutParams()).topMargin);
        }
    });

见评论..