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

在那种情况下,我没有什么想法 –