好吧我已经做了(我相信)我需要做的一切,使我的应用程序布局滚动/向上移动时,软键盘显示,但它不工作,所以我猜我必须有一些东西即时停止它,我想知道它是否固定的高度即时通讯给我的观看者或者我不知道的东西,我通过帖子阅读描述相对布局作为“破碎儿童视图”的键盘显示和线性布局没有破坏儿童视图,所以这里考虑的是我的布局
主要活动
<?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>
第三个视图
我想这个布局仍然存在当键盘弹出其当前布局的底部我把它放在一个线性布局,并尝试将其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但仍然没有任何人有任何想法的喜悦?
最佳答案 我可能会搞错,但是这个问题的原因可能是已知的Android错误.
所以,首先,你需要在< 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()方法即可使用它:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(...);
AndroidBug5497Workaround.assistActivity(this);
...
}
有关更多背景,请检查this线程.