主要活动
<?xml version="1.0" enCoding="utf-8"?><androID.support.design.Widget.CoordinatorLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"xmlns:app="http://schemas.androID.com/apk/res-auto"xmlns:tools="http://schemas.androID.com/tools"androID:layout_wIDth="match_parent"androID:layout_height="match_parent"tools:context=".MainActivity"> <relativeLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" app:layout_behavior="@string/appbar_scrolling_vIEw_behavior" androID:ID="@+ID/vIEwpagerHolder"> <androID.support.v4.vIEw.VIEwPager androID:ID="@+ID/vIEwpager2" androID:layout_wIDth="match_parent" androID:layout_marginleft="8dp" androID:layout_marginRight="8dp" androID:layout_margintop="8dp" androID:layout_height="@dimen/card_pager_height" /> <relativeLayout androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:ID="@+ID/predictsHolder" androID:layout_below="@ID/vIEwpager2"> <androID.support.v4.vIEw.VIEwPager androID:ID="@+ID/vIEwpager_predicts" androID:layout_wIDth="wrap_content" androID:layout_marginleft="8dp" androID:layout_marginRight="8dp" androID:layout_margintop="4dp" androID:layout_height="@dimen/predicts_pager_height" /> </relativeLayout> <androID.support.design.Widget.TabLayout androID:ID="@+ID/tabs" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_below="@ID/predictsHolder" app:tabGravity="fill" androID:theme="@style/CustomTabLayoutStyle" /> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_below="@ID/tabs"> <androID.support.v4.vIEw.VIEwPager androID:ID="@+ID/vIEwpager" androID:background="@color/windowBackground" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" /> </linearLayout> </relativeLayout><androID.support.design.Widget.AppbarLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content"> <androID.support.v7.Widget.Toolbar androID:ID="@+ID/toolbar" androID:layout_wIDth="match_parent" androID:layout_height="?attr/actionbarSize" /></androID.support.design.Widget.AppbarLayout><relativeLayout androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:layout_margintop="@dimen/card_pager_height"> <androID.support.design.Widget.floatingActionbutton androID:ID="@+ID/fab2" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_marginRight="12dp" androID:layout_marginEnd="12dp" app:elevation="4dp" androID:src="@drawable/ic_playList_play_white_24dp" androID:layout_gravity="right|top" androID:layout_alignParentRight="true" androID:layout_alignParentEnd="true"/></relativeLayout></androID.support.design.Widget.CoordinatorLayout>
总共有3个浏览器,每个都有不同的布局(第一个)
第一个视图
<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"xmlns:tools="http://schemas.androID.com/tools"androID:layout_wIDth="match_parent"androID:layout_height="match_parent"androID:background="@drawable/border"androID:paddingleft="2dp"androID:paddingRight="2dp"tools:context=".SpeakGrIDDB"><androID.support.v7.Widget.RecyclerVIEw androID:ID="@+ID/card_speak_grID" androID:layout_wIDth="match_parent" androID:layout_gravity="center" androID:layout_height="wrap_content"/></relativeLayout>
第二个视图
<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"androID:layout_wIDth="match_parent"androID:layout_height="wrap_content"androID:layout_margin="5dp"androID:paddingleft="2dp"androID:paddingRight="2dp"androID:background="@drawable/border"><androID.support.v7.Widget.RecyclerVIEw androID:ID="@+ID/predicts_card_speak_grID" androID:layout_wIDth="match_parent" androID:layout_gravity="center" androID:layout_height="wrap_content"/></relativeLayout>
第三个视图
我想这个布局仍然存在当键盘d出其当前布局的底部我把它放在一个线性布局,并尝试将其vIEwpager放在线性布局
<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"xmlns:tools="http://schemas.androID.com/tools"androID:layout_wIDth="match_parent"androID:layout_height="wrap_content"androID:orIEntation="vertical"androID:background="@color/windowBackground"tools:context=".OneFragment"><androID.support.v4.Widget.SwipeRefreshLayout androID:ID="@+ID/activity_main_swipe_refresh_layout" androID:layout_wIDth="match_parent" androID:background="@color/windowBackground" androID:layout_height="wrap_content"> <androID.support.v7.Widget.RecyclerVIEw androID:ID="@+ID/card_grID" androID:background="@color/windowBackground" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:clipTopadding="false"/></androID.support.v4.Widget.SwipeRefreshLayout></linearLayout>
我也在用
androID:windowsoftinputMode="adjustResize"
在我的清单中,也尝试过
androID:windowsoftinputMode="adjustPan"
但是看起来像tabLayout在显示键盘时稍微向上移动但是通常顶部的两个视图保持原位并且底部的一个(我想要显示的一个)被键盘隐藏
任何帮助表示赞赏
UPDATE
仍然没有进一步这个我可以做一个固定高度的布局,并让它完美地向上滚动所示的软键盘所以没有问题,但我必须使用布局中心垂直元素,这不是我想做的我也尝试过将它全部包装在滚动视图中并使用isScrollContainer true但仍然没有任何人有任何想法的喜悦?
所以,首先,你需要在< activity>中添加androID:windowsoftinputMode =“stateHIDden | adjustResize”.标签.
其次,您需要将此类添加到项目中:
public class AndroIDBUG5497Workaround { // For more information,see https://code.Google.com/p/androID/issues/detail?ID=5497 // To use this class,simply invoke assistActivity() on an Activity that already has its content vIEw set. public static voID assistActivity (Activity activity) { new AndroIDBUG5497Workaround(activity); } private VIEw mChildOfContent; private int usableHeightPrevIoUs; private FrameLayout.LayoutParams frameLayoutParams; private AndroIDBUG5497Workaround(Activity activity) { FrameLayout content = (FrameLayout) activity.findVIEwByID(androID.R.ID.content); mChildOfContent = content.getChildAt(0); mChildOfContent.getVIEwTreeObserver().addOnGlobalLayoutListener(new VIEwTreeObserver.OnGlobalLayoutListener() { public voID onGlobalLayout() { possiblyResizeChildOfContent(); } }); frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams(); } private voID possiblyResizeChildOfContent() { int usableHeightNow = computeUsableHeight(); if (usableHeightNow != usableHeightPrevIoUs) { int usableHeightSansKeyboard = mChildOfContent.getRootVIEw().getHeight(); int heightDifference = usableHeightSansKeyboard - usableHeightNow; if (heightDifference > (usableHeightSansKeyboard/4)) { // keyboard probably just became visible frameLayoutParams.height = usableHeightSansKeyboard - heightDifference; } else { // keyboard probably just became hIDden frameLayoutParams.height = usableHeightSansKeyboard; } mChildOfContent.requestLayout(); usableHeightPrevIoUs = usableHeightNow; } } private int computeUsableHeight() { Rect r = new Rect(); mChildOfContent.getwindowVisibledisplayFrame(r); return (r.bottom - r.top); }}
然后只需在包含VIEwPagers的MainActivity中调用assistActivity()方法即可使用它:
@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(...); AndroIDBUG5497Workaround.assistActivity(this); ...}
有关更多背景,请检查this线程.
总结以上是内存溢出为你收集整理的当使用viewpagers显示软键盘时,android移动布局全部内容,希望文章能够帮你解决当使用viewpagers显示软键盘时,android移动布局所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)