Android Scroll Container - 焦点时看不到EditText

时间:2015-07-07 10:37:14

标签: android android-layout

我有一个关于android布局文件的小问题,当用户触摸EditText键盘出现但隐藏键盘后面的edittext ...这是因为我将登录按钮保持在键盘上方...

我的XML文件如下所示:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#ffffff"
                android:clickable="true"
                android:orientation="vertical">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:isScrollContainer="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">


            <LinearLayout
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:layout_weight="5"
                android:orientation="vertical"
                android:paddingLeft="25dp"
                android:paddingRight="25dp">

                <ImageView
                    android:layout_width="fill_parent"
                    android:layout_height="100dp"
                    android:contentDescription="logo"
                    android:paddingTop="10dp"
                    android:src="@drawable/ic_launcher"/>


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="30dp"
                    android:text="Driver ID"
                    android:textColor="@color/red"/>

                <EditText
                    android:id="@+id/driver_id"
                    android:layout_width="match_parent"
                    android:layout_height="35dp"
                    android:background="@drawable/rounded_text"
                    android:hint="Only digits allowed"
                    android:inputType="number"
                    android:text="1"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="30dp"
                    android:text="Registration"
                    android:textColor="@color/red"/>

                <EditText
                    android:id="@+id/registration"
                    android:layout_width="match_parent"
                    android:layout_height="35dp"
                    android:background="@drawable/rounded_text"
                    android:hint="Only letters and digits allowed"
                    android:inputType="text|textCapCharacters|textNoSuggestions"
                    android:text="KV61 YVZ"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="30dp"
                    android:text="Pin"
                    android:textColor="@color/red"/>

                <EditText
                    android:id="@+id/pin"
                    android:layout_width="match_parent"
                    android:layout_height="35dp"
                    android:background="@drawable/rounded_text"
                    android:hint="Please Enter your pin"
                    android:imeOptions="actionSend"
                    android:inputType="numberPassword"
                    android:text="9999"/>

            </LinearLayout>


        </LinearLayout>

    </ScrollView>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:paddingTop="10dp">

        <Button
            android:id="@+id/logon_btn"
            android:layout_width="match_parent"
            android:layout_height="55dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:background="@color/green"
            android:text="Log On"
            android:textColor="@color/black"
            android:textSize="21dp"
            android:textStyle="bold"/>

    </RelativeLayout>

</RelativeLayout>

以下是一些截图: 键盘没有显示: Keyboard not showing

键盘显示: Keyboard showing

我希望这样当用户触摸“pin”EditText时,他们可以看到他们正在键入的内容。在此先感谢:)

我尝试过以下修复:  

这不起作用。还有其他提示吗?谢谢:))

2 个答案:

答案 0 :(得分:3)

在清单中,您需要将windowSoftInputMode设置为adjustPan以进行活动

<activity android:name="your activity"
           android:windowSoftInputMode="adjustPan">
 </activity>

答案 1 :(得分:1)

巴鲁对他的回答是半正确的

AndroidManifest.xml的activity标记中的

android:windowSoftInputMode="adjustPan"

但我还需要添加

 android:isScrollContainer="true"

到我的滚动视图。

  <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/backlayout"
        android:isScrollContainer="true"
        android:orientation="vertical"
        android:paddingTop="10dp">

 </ScrollView>
相关问题