我的活动的下一个布局是:
有时,在viewPager中,我有一个具有EditText的片段。
在某些屏幕上(比如galaxy mini),我注意到当你点击一个editText(为了写入它)时,软键盘会隐藏所有内容,所以你只剩下actionBar,标签和状态栏。
这就是为什么我决定在此活动的清单上添加下一个标志:
android:windowSoftInputMode="adjustPan|adjustResize|stateHidden"
这看起来是完美的解决方案 - 它在输入时隐藏了操作栏,标签甚至状态栏,为editText留下了足够的空间来显示(并且还滚动到它)。
然而,在更大的屏幕(如Galaxy S3)上测试它,这导致softKeyboard在editText位于底部的情况下覆盖editText。
我试图删除adjustPan标志,该标志适用于大屏幕,但随后在小屏幕上,即使它已滚动到editText,状态栏也会隐藏它。
我还尝试将isScrollContainer设置为true来处理某些视图,希望它会导致它们在编辑时调整大小,但它没有做任何事情。
我可以做些什么来解决这个问题,并处理各种屏幕?
我可以检查屏幕的类型并以编程方式使用适当的标志(如here),但我不确定应该是什么规则(密度/分辨率/屏幕大小),如果我真的涵盖所有类型。
答案 0 :(得分:1)
尝试android:windowSoftInputMode="adjustPan
附加功能
制作另类课程
package com.example.customLayout;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
public class MyRelativeLayout extends RelativeLayout
{
private OnRelativeLayoutChangeListener layoutChangeListener;
public interface OnRelativeLayoutChangeListener
{
void onLayoutPushUp();
void onLayoutPushDown();
}
public MyRelativeLayout(Context context, AttributeSet attributeSet)
{
super(context, attributeSet);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
try
{
final int proposedheight = MeasureSpec.getSize(heightMeasureSpec);
final int actualHeight = getHeight();
if (actualHeight > proposedheight)
{
// Keyboard is shown
layoutChangeListener.onLayoutPushUp();
}
else if(actualHeight < proposedheight)
{
// Keyboard is hidden
layoutChangeListener.onLayoutPushDown();
}
}
catch (Exception e)
{
e.printStackTrace();
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
public void setLayoutChangeListener(OnRelativeLayoutChangeListener layoutChangeListener)
{
this.layoutChangeListener = layoutChangeListener;
}
public OnRelativeLayoutChangeListener getLayoutChangeListener()
{
return layoutChangeListener;
}
}
现在将此类的客户视图作为布局xml文件中的父级视图,如此
<com.example.customLayout.MyRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res/com.example.customLayout"
android:id="@+id/customRelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
// your original layout file
</com.example.customLayout.MyRelativeLayout>
尝试使用java文件中的代码
myRelativeLayout =(MyRelativeLayout)findViewById(R.int.customRelativeLayout);
myRelativeLayout.setLayoutChangeListener(new OnRelativeLayoutChangeListener() {
public void onLayoutPushUp()
{
Controller_Test1.tabWidget.setVisibility(View.GONE);
}
public void onLayoutPushDown()
{
Controller_Test1.tabWidget.setVisibility(View.VISIBLE);
}
});