2014-02-21 30 views
2

我遇到了这个大问题:当我点击edittext并且键盘向上时,键盘覆盖按钮。我在网上搜索了解决方案,但调整了resize,adjustpan不起作用。我也尝试使用getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);,但不起作用。Android-如何在键盘启动时自动滚动

<?xml version="1.0" encoding="utf-8"?> 
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/scrollView1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/sfondo3" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:isScrollContainer="true" 
    > 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center_horizontal" > 

    <TextView 
     android:id="@+id/nickname" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="200dp" 
     android:text="Inserisci un Nickname:" 
     android:textSize="20dp" /> 

    <Button 
     android:id="@+id/b1" 
     android:layout_width="120dp" 
     android:layout_height="50dp" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="350dp" 
     android:text="Accedi" /> 



    <EditText 
     android:id="@+id/editText1" 
     android:layout_width="200dp" 
     android:layout_height="50dp" 
     android:layout_marginTop="250dp" 
      android:windowSoftInputMode="adjustPan" 
     android:layout_centerHorizontal="true" 
     android:ems="10" /> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="20dp" 
     android:src="@drawable/logox" /> 



</RelativeLayout> 
</ScrollView> 

回答

1

您可以尝试在AndroidManifest.xml文件中声明windowSoftInputMode如下。当显示键盘时,它会填充强制活动以调整其大小。

<activity android:name="YourActivityName" 
      android:windowSoftInputMode="adjustResize"> 

如果这没有帮助,你可能想实现this thread提出了一个更复杂的解决方案。

+0

刚刚尝试过,它不起作用... –