关于Edittext点击弹出软键盘,布局上移标题消失问题,微信聊天界面

来源:互联网 发布:网络最火的英文歌曲 编辑:程序博客网 时间:2024/04/29 17:32

 最近遇到了关于软键盘弹出,布局上移动的解决

                                


当edittext获取焦点呢,弹出软键盘,布局上移,标题位置不变,

1,取消activity设置, Activity 设置 android:windowSoftInputMode=""

2.主布局增加Scrollview包裹主布局,并且设置属性

android:fillViewport="true" 

<?xml version="1.0" encoding="utf-8"?><ScrollView xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="match_parent"    android:fillViewport="true" >
3,关于

当ScrollView里的元素想填满ScrollView时,使用"fill_parent"是不管用的,必需为ScrollView设置:android:fillViewport="true"。

 当ScrollView没有fillVeewport=“true”时, 里面的元素(比如LinearLayout)会按照wrap_content来计算(不论它是否设了"fill_parent"),

而如果LinearLayout的元素设置了fill_parent,那么也是不管用的,因为LinearLayout依赖里面的元素,而里面的元素又依赖LinearLayout,

这样自相矛盾.所以里面元素设置了fill_parent,也会当做wrap_content来计算.

<!-- 设置fillViewport属性表示充满整个ScrollView --> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <LinearLayout android:id="@+id/logo" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="20dip" android:layout_weight="1" android:gravity="bottom|center_horizontal" android:orientation="vertical" > <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ImageView android:id="@+id/serviceimg" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> <FrameLayout android:id="@+id/layout_main" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="top|center_horizontal" android:orientation="vertical" android:visibility="visible" > </FrameLayout> <RadioGroup android:id="@+id/radioGroup" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <RadioButton android:id="@+id/bu1" android:layout_width="wrap_content" android:background="#da1111" android:text="聊天界面" android:layout_height="wrap_content" /> <RadioButton android:id="@+id/bu2" android:layout_width="wrap_content" android:background="#ffaa12" android:button="@null" android:text="聊你妹啊" android:layout_height="wrap_content" /> </RadioGroup> </LinearLayout></ScrollView>
试试吧,测试没问题
2。附加一个简单检测软键盘的弹出,通过软键盘是否弹出,隐藏底部菜单。
main_cro.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {    @Override    public void onLayoutChange(View v, int left, int top, int right,                               int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {        //Toast.makeText(v.getContext(),bottom+"|"+oldLeft+"|"+oldTop+"|"+oldBottom,Toast.LENGTH_LONG).show();        if((bottom-oldBottom)<-100){            radioGroup.setVisibility(View.GONE);        }if((bottom-oldBottom)>200){            radioGroup.setVisibility(View.VISIBLE);        }    }});
main_cro是主布局id,根据参数调试。。


1 0
原创粉丝点击