2016-12-06 8 views
4

ok私は自分のアプリケーションのレイアウトをスクロール/移動させるために必要なすべてのことをソフトキーボードが表示されているが動作していませんそれを止めている何かがなければならない、私はその固定された高さが私のviewpagesや何かを知らないことに気づいていないのだろうか?キーボードが表示され、線形レイアウトが壊れていないときに相対レイアウトを 'これを念頭に置いて、ここで、子ビューは、私のレイアウトはアンドロイドはビューパッドを使ってソフトキーボードを表示したときにレイアウトを移動します

MAIN_ACTIVITY

<?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 viewpagersの合計は、それぞれ異なるレイアウト最初の(一番上の)

FIRST VIEWPAGER

<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> 

SECOND VIEWPAGER

<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> 

THIRD 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> 

をそのviewpagerを入れてみましたがポップアップしたときに、このレイアウトはまだ存在になりたい

また、私のマニフェストで

 android:windowSoftInputMode="adjustResize" 

を使用しても

 android:windowSoftInputMode="adjustPan" 

を試してみましたが、それはtabLayoutように思える何の喜びは少し際KEYBシフトアップしませんoardは、私は、レイアウトを作ることができる示すが、一般的に上の2つのビューは、場所に滞在し、下の1(私は示されたい1)は、任意のヘルプがこれに まだありませんさらに

UPDATEを高く評価されているキーボード によって隠されています固定された高さをwithtとソフトキーボードと完全にスクロールするので問題はないが、私は要素にレイアウトの垂直を使用する必要がありますこれは私が欲しいものは何もスクロールビューですべてをラップしようとisScrollContainer真実だがまだ誰も何の喜びもない?

+0

キーボードが表示されたらFABが上に移動しますか? –

+0

@ダルシャンmiskinいいえ、私はファンにそれがレイアウトでかなり高いですし、影響を受けるべきではありません –

答えて

1

android:fitsSystemWindows="true"を追加してみてくださいすることができます私は勘違いかもしれないが、この問題の原因は、おそらく知られているAndroidのバグです。

ので、は、まず、あなたの<activity>タグ内android:windowSoftInputMode="stateHidden|adjustResize"を追加する必要があります。

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(...); 
    AndroidBug5497Workaround.assistActivity(this); 
    ... 
} 

:ViewPagersを保持しているあなたのMainActivityassistActivity()メソッドを呼び出すことにより、

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); 
    } 

} 

そして、単にそれを使用します。

は、第二は、あなたのプロジェクトにこのクラスを追加する必要があります詳細については、thisスレッドを確認してください。

+0

こんにちは@ rom4ek最初にありがとう、このクラスLOL iveのための素晴らしい名前は、キーボードがレイアウト変更が表示されますが、私が探していたときに、キーボードが隠されているレイアウトは正常に戻りますが、これを作成しましたか?もしそうなら、私はこの完璧な私がこの行の何かを推測するために試して調整する必要があるでしょうか?frameLayoutParams.height = usefulHeightSansKeyboard - heightDifference;今は空白の画面で終わるだけです –

+0

キーボードが表示されているので、画面が空白になっていますか? – rom4ek

+0

これは空白ではありません。実際にビューページを保持するレイアウトの私の背景です。このフレームにラインを変更しました.LayoutParams.height = usefulHeightSansKeyboard - heightDifference/2;私はまだ私のレイアウトの上部の半分を見ることができます(明らかに) –

0

あなたのコーディネーターのレイアウト

+0

それは何をするだろうとどこに追加する必要がありますいくつかの解説は参考になります。 –

+0

ありがとう私はこれを試みたが、変更はなかった –

関連する問題