Android 在小屏幕上处理编辑文本编辑 背景
我有我的活动的下一个布局:Android 在小屏幕上处理编辑文本编辑 背景,android,scroll,android-edittext,android-screen-support,Android,Scroll,Android Edittext,Android Screen Support,我有我的活动的下一个布局: 垂直线性布局 带有viewPager的TabHost “状态栏”(图像视图/文本视图) 有时,在viewPager中,我有一个片段,其中包含EditText 问题 在一些屏幕上(比如galaxy mini),我注意到当你点击编辑文本(为了写入),软键盘会隐藏所有内容,所以你只剩下操作栏、选项卡和状态栏 我试过的 这就是为什么我决定在清单上为此活动添加下一个标志: android:windowSoftInputMode="adjustPan|adjustResi
- 垂直线性布局
- 带有viewPager的TabHost李>
- “状态栏”(图像视图/文本视图)
android:windowSoftInputMode="adjustPan|adjustResize|stateHidden"
这看起来是一个完美的解决方案——它在键入时隐藏了操作栏、选项卡,甚至是状态栏,为编辑文本留下了足够的显示空间(也可以滚动到编辑文本)
然而,在更大的屏幕上测试它(比如galaxy S3),这导致在editText位于底部的情况下,软键盘覆盖了editText
我尝试删除adjustPan标志,它在大屏幕上运行良好,但在小屏幕上,即使它已滚动到editText,状态栏也会将其隐藏
我还尝试将某些视图的设置为true,希望它能使它们在编辑时调整大小,但它没有做任何事情
问题
要解决此问题并处理各种屏幕,我可以做些什么
我可以通过编程检查屏幕类型并使用适当的标志(如),但我不确定规则应该是什么(密度/分辨率/屏幕大小),以及我是否真的涵盖了所有类型。试试
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;
}
}
所以你实际上是在提供检测软键盘可见性的方法,如果出现这种情况,我会选择隐藏什么,对吗?你选择RelativeLayout的具体原因是什么?是的,你是对的。因为android无法检测到软键盘是否打开,或者不是我在面对与你相同的问题时发现的唯一解决方案o使用这个解决方案,它工作得很好。没有任何特定的理由使用RelayLayOut.我知道.好的解决方案.但是,我发现,因为我的片段有一个滚动视图,使用平移标志有一个问题:如果你在滚动轴的中间,按下EdvEdt文本,然后在显示软键盘时尝试滚动,这样ftKeyboard仍将隐藏scrollView的底部视图。为什么会发生这种情况?有没有办法解决它?我不知道为什么adjustpan在您的案例中不起作用。请尝试更改包含选项卡的父级活动中的adjustpan和adjustResize选项。我的意思是,在该活动中,您将选项卡添加到tabhost。我不确定是否理解,但添加“adjustResize“将导致我报告的galaxy s3问题-打开软键盘时,它不会自动滚动到编辑文本。
<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>
myRelativeLayout.setLayoutChangeListener(new OnRelativeLayoutChangeListener() {
public void onLayoutPushUp()
{
Controller_Test1.tabWidget.setVisibility(View.GONE);
}
public void onLayoutPushDown()
{
Controller_Test1.tabWidget.setVisibility(View.VISIBLE);
}
});