移动的布局时,软键盘吗?
-
21-09-2019 - |
题
我有几个因素中的一个RelativeView与准底设定的属性,在软盘来的元素是隐藏的软盘。
我想他们动起来,这样,如果有足够的画面的空间中它们显示上的键盘,或使上述部分的键盘滚动以用户仍然可以看到的要素。
任何想法,如何处理这个吗?
解决方案
是,检查出本文就Android开发网站介绍如何框架手柄软键盘出现。
在android:windowSoftInputMode
属性可以被用来指定在每个活动基础会发生什么:布局是否被调整大小,或是否滚动等
其他提示
您也可以在onCreate()
方法使用以下代码:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
添加在AndroidManifest.xml你的活动:
android:windowSoftInputMode="adjustPan|adjustResize"
请在你的清单文件的活动变化像
windowSoftInputMode="adjustResize"
或强>
请您onCreate()
方法改变在活动类等
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
类似问题我正面临与我的布局,其由滚动视图的内部。 每当我试图在EditText上,复制/剪切选择文本/粘贴操作栏被移到了下面的代码因此它不会调整大小布局
android:windowSoftInputMode="adjustPan"
通过将其修改为以下
1)的AndroidManifest.xml
android:windowSoftInputMode="stateVisible|adjustResize"
2)style.xml文件,在活动式
<item name="android:windowActionBarOverlay">true</item>
它的工作。!!!!!!!!!!!!
在AndroidManifest.xml中,不要忘记组:
android:windowSoftInputMode="adjustResize"
和用于RelativeLayout的内部滚动型,设置:
android:layout_gravity="center" or android:layout_gravity="bottom"
这将是好
用于以下行其OnCreate中梅索德插入活动
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
和在其onCreate方法片段
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
有3个步骤,按照滚动屏幕了。
- 写在清单文件对于您的活动:
问题:windowSoftInputMode="adjustResize"
- 添加以下行oncreate()方法的活动
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
- 然后把你的整个图在"滚动型"在XML文件,如:
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:background="@drawable/bg" android:layout_height="match_parent" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_gravity="center" > <TextView /> ......... <TextView /> <EditText > <requestFocus /> </EditText> <Button /> </RelativeLayout> </ScrollView>
P.S.不要忘记加入问题:layout_gravity="中心"为父母的相对布局。
我试图迭Ramírez的的方法,它的工作原理。 在AndroidManifest:
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateHidden|adjustResize">
...
</activity>
在activity_main.xml中:
<LinearLayout ...
android:orientation="vertical">
<Space
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" />
<EditText
android:id="@+id/edName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/first_name"
android:inputType="textPersonName" />
<EditText ...>
...
</LinearLayout>
我发现我的问题的解决方案,这是很一样的你。
首先,我只有2个元素,一个ImageView的和至极含有2的EditText和一个按钮的LinearLayout一个的LinearLayout,所以我需要让他们分开在全屏幕无键盘,而键盘出现时,他们应该看看近。
因此,我增加它们之间的视图与0dp和权重1的高度属性,让我保存我的意见中分离一种形成彼此。当键盘appers,因为他们没有一个固定的高度,他们只是调整和保持方面。
瞧!布局调整大小和我的视图之间的距离是相同的,当键盘或不存在。
下面是满清单代码
<activity
android:name=".activities.MainActivity"
android:windowSoftInputMode="adjustResize"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
如果你在碎片,那么你必须添加下面的代码到你的onCreate您的活动能解决问题,我
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
在您的清单文件中添加以下行。它将工作
<activity name="MainActivity"
android:windowSoftInputMode="stateVisible|adjustResize">
...
</activity>
好吧,这是非常晚但我发现,如果你在你的编辑文本添加列表视图,则该键盘将动议的EditText下的所有布局,而无需移动的ListView
<EditText
android:id="@+id/et"
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"//can make as 1dp
android:layout_below="@+id/et" // set to below editext
android:id="@+id/view"
>
**<any layout**
这是唯一的解决方案,为我工作。
Here is the solution for this fix
- android:windowSoftInputMode="adjustResize" in Manifest File
- Make a class "CommentKeyBoardFix.Java" and copy and paste the below code.
public class CommentKeyBoardFix
{
private View mChildOfContent;
private int usableHeightPrevious;
private FrameLayout.LayoutParams frameLayoutParams;
private Rect contentAreaOfWindowBounds = new Rect();
public CommentKeyBoardFix(Activity activity)
{
FrameLayout content = activity.findViewById(android.R.id.content);
mChildOfContent = content.getChildAt(0);
mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(this::possiblyResizeChildOfContent);
frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
}
private void possiblyResizeChildOfContent()
{
int usableHeightNow = computeUsableHeight();
if (usableHeightNow != usableHeightPrevious)
{
int heightDifference = 0;
if (heightDifference > (usableHeightNow /4))
{
// keyboard probably just became visible
frameLayoutParams.height = usableHeightNow - heightDifference;
}
else
{
// keyboard probably just became hidden
frameLayoutParams.height = usableHeightNow;
}
mChildOfContent.layout(contentAreaOfWindowBounds.left, contentAreaOfWindowBounds.top, contentAreaOfWindowBounds.right, contentAreaOfWindowBounds.bottom);
mChildOfContent.requestLayout();
usableHeightPrevious = usableHeightNow;
}
}
private int computeUsableHeight()
{
mChildOfContent.getWindowVisibleDisplayFrame(contentAreaOfWindowBounds);
return contentAreaOfWindowBounds.height();
}
}
And then call this class in your Activity or Fragment
setContentView(R.layout.your_comments_layout)
CommentKeyBoardFix(this) ---> For Kotlin
or
new CommentKeyBoardFix(this) ---> For Java
我刚添加下列行来顶层布局和一切工作:
android:fitsSystemWindows="true"