繁体   English   中英

设置android时如何滚动我的布局:windowSoftInputMode =“adjustPan”?

[英]How to scroll my layout when setting android:windowSoftInputMode=“adjustPan”?

我的活动有一个顶栏和一个底栏。 topbar和bottom bar之间的空间我有一个linearlayout,里面有几个edittext视图。 因为我不希望每次软键盘出现时我的布局都会调整大小,所以我为manifest中的活动设置了android:windowSoftInputMode =“adjustPan”。 但是当打开软键盘时,我想向下滚动以选择另一个要输入的编辑文本,这是不允许我这样做的。 我只能在关闭软键盘时选择底部的edittext。 这非常烦人且不方便。 如何才能同时获得软键盘的scrollview和ajustpan模式?

请帮帮我。 非常感谢。

最后,我找到了我的问题的解决方法,所以我想分享给某人可能会在将来遇到同样的问题。 我的布局简要描述如下:

<myRelativeLayout>
<topbar.../>
<myscrollView>
    <linearLayout>
        //all stuff controls:editview,textview,....
    </linearLayout>
</myscrollView>
<bottombar.../>

我创建自定义类myRelativeLayout扩展RelativeLayout

public class myRelativeLayout extends RelativeLayout{

public interface OnRelativeLayoutChangeListener {
    void onLayoutPushUp();
    void onLayoutPushDown();
}

private OnRelativeLayoutChangeListener layoutChangeListener;
public myRelativeLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    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();
    }       
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

public void setLayoutChangeListener(OnRelativeLayoutChangeListener layoutChangeListener) {
    this.layoutChangeListener = layoutChangeListener;
}

public OnRelativeLayoutChangeListener getLayoutChangeListener() {
    return layoutChangeListener;
}

}

在我的活动中,我只是为myRelativeLayout设置setLayoutChangeListener以在软键盘显示时隐藏底栏并在软键盘隐藏时显示底栏:

myRlayout.setLayoutChangeListener(new OnRelativeLayoutChangeListener() {

        @Override
        public void onLayoutPushUp() {
            // TODO Auto-generated method stub
            myBottombar.setVisibility(View.GONE);//in my case i need to setVisibility(View.GONE) to bottombar in order for this bar is not displayed when softkeyboard show up.
        }

        @Override
        public void onLayoutPushDown() {
            // TODO Auto-generated method stub
            myBottombar.setVisibility(View.VISIBLE);// redisplay myBottombar when keyboard is closed.

        }
    });

不要忘记为活动设置android:windowSoftInputMode =“adjustResize”。 希望这对有人遇到同样问题很有用。

将这些EditText放在ScrollView如下所示:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <requestFocus />
        </EditText>

        <EditText
            android:id="@+id/editText2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <EditText
            android:id="@+id/editText3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>

</ScrollView>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM