1

我試圖做的唯一事情就是在頂部會有一個editText,然後會有一個ImageView。 現在最後一行會出現一些按鈕(例如表情符號),只有在軟鍵盤出現時纔會將其底部向上推。當軟鍵盤出現時,只將底部向上推

我通過附加Facebook的佈局使其更加清晰。 required output

我已經經歷了所有這些SO問題,也嘗試了他們的答案,但沒有運氣。可能是我做錯了什麼。

Android: Resize only parts of view with soft keyboard on screen

Android: How do I prevent the soft keyboard from pushing my view up?

android : How to prevent resizing the window when displaying the virtual keyboard

我的XML代碼

<ScrollView 
    android:id="@+id/scrollOnPost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:isScrollContainer="false" 
    android:fillViewport="true" 
    android:layout_below="@+id/header_layout"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:weightSum="4" 
    android:layout_gravity="bottom" 
    android:gravity="bottom"> 
<EditText 
      android:id="@+id/ed_post" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"/> 
<ImageView 
     android:id="@+id/img_posted_list_row" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="2.7" 
     android:adjustViewBounds="true" 
     android:src="@mipmap/ic_launcher" 
     android:scaleType="fitCenter" 
     android:background="@color/red"/> 

</LinearLayout> 
</ScrollView> 

<ImageButton 
    android:id="@+id/imgBtn_Emoji" 
    android:layout_width="40dp" 
    android:layout_height="40dp" 
    android:layout_alignParentBottom="true" 
    android:src="@drawable/smile_face" 
    android:background="@drawable/button_pressed_white" 
    /> 

所有我得到我的軟鍵盤總是把整個佈局了不是在底部剛表情符號。謝謝。

+0

看到這個鏈接它可能會幫助你:http://stackoverflow.com/questions/17410499/difference-between-adjustresize-and-adjustpan-in-android –

+0

感謝鏈接庫納爾。我已經嘗試了「adjustResize」,「adjustPan」,並且兩者都在清單中,但結果不是我所需要的。但問題是我有同樣的問題。再次感謝。 –

+0

@ Md。Asaduzzaman Noor il嘗試在我的代碼中添加布局,以及c我可以找到什麼解決方案 –

回答

0

多德它的工作 清單:

<activity android:name=".TestActivity" 
     android:windowSoftInputMode="adjustResize"/> 

XML:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView android:id="@+id/scrollOnPost" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:isScrollContainer="false" 
android:fillViewport="true" 
android:layout_below="@+id/header_layout" 
xmlns:android="http://schemas.android.com/apk/res/android"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:weightSum="4" 
    android:layout_gravity="bottom" 
    android:gravity="bottom"> 
    <EditText 
     android:id="@+id/ed_post" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 
    <ImageView 
     android:id="@+id/img_posted_list_row" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="2.7" 
     android:adjustViewBounds="true" 
     android:scaleType="fitCenter" 
     android:background="@color/colorPrimary"/> 
    <ImageButton 
     android:id="@+id/imgBtn_Emoji" 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:layout_alignParentBottom="true" 
     android:src="@mipmap/call" 
     /> 
</LinearLayout> 

我猜你只想要EDITTEXT推升時,鍵盤是可見的(糾正我,如果我錯)因爲我有一個想法,我不知道它是否會工作或不,你可以試試看,如果你發現它邏輯

想法是首先檢查鍵盤是否可見,其次如果可見,請獲取其高度並以編程方式爲您的佈局指定一個等於鍵盤高度(使用layoutParams)的marginBottom。

檢查該鏈接爲實現上述想法:

How to capture the "virtual keyboard show/hide" event in Android?

Is there any way in android to get the height of virtual keyboard of device

How to set RelativeLayout layout params in code not in xml

before clicking edit text

after clicking edit text

+0

感謝您試圖幫助@Kunal,但它無法正常工作,請查看附件圖片,並嘗試理解我的要求。 –

+0

感謝您的建議庫納爾,但我很久以前就明白了這個想法,並且嘗試過。但它並不適用於所有類型的設備,因此它不是最佳實踐。我只是想知道Facebook做到這一點。而已。 –

+0

在那種情況下,我沒有什麼想法 –