2017-07-27 1 views
2

Ich möchte mein Layout verschieben, wenn die Tastaturen in meiner App angezeigt wird. Ich habe adjustResize, adjustPan und beide für die Aktivität verwendet, aber keiner von ihnen funktioniert und es zeigt immer noch die Tastatur auf dem Formular und bewegt das Layout nicht über.android - Tastatur zeigt auf Formular trotz Verwendung von adjustResize

das ist mein Layout:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      ............... my views 

     </LinearLayout> 
    </ScrollView> 
</RelativeLayout> 

wie kann ich es funktioniert machen?

+0

Versuchen Sie, android: isScrollContainer = "false" mit Android : windowSoftInputMode = "adjustNothing" oder android: windowSoftInputMode = "adjustPan" –

Antwort

1

versuchen, wie diese

final View activityRootView = findViewById(R.id.activityRoot); 
     activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 
      @Override 
      public void onGlobalLayout() { 
       int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight(); 
       if (heightDiff > dpToPx(getApplicationContext(), 200)) { // if more than 200 dp, it's probably a keyboard... 
        // ... do something here 
       } 
      } 
     }); 


public static float dpToPx(Context context, float valueInDp) { 
     DisplayMetrics metrics = context.getResources().getDisplayMetrics(); 
     return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, valueInDp, metrics); 
    } 

andjust diese
android in Ihrem xml hinzufügen: id = "@ + id/activityRoot"

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    **android:id="@+id/activityRoot"**> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      ............... my views 

     </LinearLayout> 
    </ScrollView> 
</RelativeLayout> 
+0

danke für die Antwort, was soll ich in onGlobalLayout Methode tun? –

+0

nichts das ist genug. Es hat für mich funktioniert. –

Verwandte Themen