簡體   English   中英

鍵盤未在上方滾動EditText

[英]Keyboard is not scrolling EditText above

我正在使用此代碼。 但是,當我單擊EditText打開鍵盤時,視圖並沒有完全打開。 為什么視圖不能一直向上顯示,EditText隱藏在鍵盤后面

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    android:background="@drawable/main_bg" 
    android:id="@+id/mainLayout"
    android:focusableInTouchMode="true"
    >

       <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:orientation="horizontal"
        android:id="@+id/topBar"
        android:background="@drawable/top_bar_bg"
     >

        <LinearLayout 
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:orientation="horizontal"
                android:gravity="center_horizontal|bottom"
                android:layout_centerInParent="true"
            >

                 <ImageView 
                     android:id="@+id/loadingAnimationImg"
                     android:layout_height="35dp"
                     android:layout_width="35dp"
                     android:adjustViewBounds="true"
                     android:contentDescription="@null"
                     android:background="@drawable/img05"/>

                 <ImageView 
                     android:layout_marginBottom="5dp"
                     android:layout_height="wrap_content"
                     android:layout_width="120dp"
                     android:adjustViewBounds="true"
                     android:contentDescription="@null"
                     android:src="@drawable/simple_logo"/>

         </LinearLayout>
    </RelativeLayout>

    <GridView
            android:layout_marginTop="5dp"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:id="@+id/gridView"
            android:numColumns="5"
            android:verticalSpacing="5dp" />

    <TextView 
        android:layout_marginTop="5dp"
        android:layout_marginLeft="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="12sp"
        android:textColor="@android:color/white"
        android:text="@string/hashtagText"
        />


    <com.trib.devicebee.custom.FlowLayout 
        android:id="@+id/flowLayout"
        android:layout_margin="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

    <EditText 
        android:layout_margin="10dp"
        android:id="@+id/hashTagsText"
        android:hint=""
        android:inputType="textFilter" 
        android:singleLine="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="12sp"
        />

    <Button
        android:id="@+id/goAheadBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/go_ahead_btn"
        android:layout_margin="10dp"
         />

</LinearLayout>

嘗試使用AndroidManifest.xml中的android:windowSoftInputMode屬性- “ adjustPan”可能是答案。

<activity
    android:name="MyActivity"
    android:windowSoftInputMode="adjustPan"
    android:configChanges="orientation|keyboardHidden|screenSize"
    >
</activity>

我想出的最好的解決方案是將所有內容放入scrollView中

  • 現在很明顯

     <activity android:name="MyActivity" android:windowSoftInputMode="adjustResize"> </activity> 
  • 現在,在要聚焦的editText上使用onfocusChangeListener

     editText.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean b) { if (b){ scrollView.smoothScrollTo(0,editText.getBottom()+5); } } }); 

我們完成了。

https://developer.android.com/training/keyboard-input/visibility.html

機器人:windowSoftInputMode = “adjustResize”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM