【问题标题】:Android- how to autoscroll when keyboard is upAndroid-键盘启动时如何自动滚动
【发布时间】:2014-02-22 02:53:43
【问题描述】:

我遇到了一个大问题:当我单击edittext 并且键盘启动时,键盘覆盖了按钮。我已经在网上搜索了解决方案,但adjustresize、adjustpan 不起作用。我也尝试过使用getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);,但不起作用。

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

【问题讨论】:

    标签: android xml layout scroll keyboard


    【解决方案1】:

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

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

    如果这没有帮助,您可能需要实施this thread 中建议的更复杂的解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多