键盘缩小EditText

时间:2016-08-04 04:55:26

标签: android android-layout android-softkeyboard

我的布局中有三个EditText。当我点击它们中的任何一个然后它缩小我的布局并且第二个布局几乎不可见。我希望当我点击第二个布局("亲爱的父母")时,键盘应该与最后一个edittext(教师名称)重叠,当我点击最后一个edittext时,它应该出现在键盘上方。 以下是截图

enter image description here enter image description here

这是代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/actionbar_title_color"
    android:orientation="vertical">

    <include
        android:id="@+id/include"
        layout="@layout/toolbar" />

    <android.support.v7.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="25dp"
        android:layout_marginLeft="25dp"
        android:layout_marginRight="25dp"
        android:layout_marginTop="25dp"
        card_view:cardElevation="10sp"
        card_view:cardUseCompatPadding="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"

            android:background="#ffffff"
            android:orientation="horizontal">

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_marginTop="10dp"
                android:layout_weight="1"
                android:background="@drawable/filebinder" />

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="14"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="10dp"
                    android:orientation="horizontal">


                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="6"
                        android:orientation="vertical">

                        <TextView
                            android:id="@+id/dateDiary"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="10dp"
                            android:fontFamily="sans-serif"
                            android:text="30 July"
                            android:textColor="#03a9f4"
                            android:textSize="20sp" />

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="1dp"
                            android:layout_marginBottom="10dp"
                            android:background="#03a9f4" />

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:background="@drawable/diarybookmark" />

                </LinearLayout>

                <ScrollView
                    android:id="@+id/scrollView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp">

                    <EditText
                        android:id="@+id/diaryHeading"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:layout_margin="10dp"
                        android:ems="5"
                        android:fontFamily="sans-serif"
                        android:hint="Diary Heading"
                        android:inputType="textPersonName"
                        android:textAlignment="center"
                        android:textColor="#000000"
                        android:textSize="18sp" />
                </ScrollView>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">


                    <EditText
                        android:id="@+id/diaryTeacherName"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true"
                        android:layout_gravity="center"
                        android:fontFamily="sans-serif"
                        android:hint="Teacher\'s Name..."
                        android:textSize="16sp" />


                    <at.markushi.ui.CircleButton
                        android:id="@+id/addDiaryEntry"
                        android:layout_width="74dip"
                        android:layout_height="74dip"
                        android:layout_gravity="right"
                        android:src="@drawable/ic_action_tick"
                        app:cb_color="@color/actionbar_title_color"
                        app:cb_pressedRingWidth="8dip"
                        android:layout_alignParentBottom="true"
                        android:layout_alignParentRight="true"
                        android:layout_alignParentEnd="true" />

                    <EditText
                        android:id="@+id/diaryContent"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_above="@+id/addDiaryEntry"
                        android:layout_alignLeft="@+id/scrollView"
                        android:layout_alignStart="@+id/scrollView"
                        android:layout_alignTop="@+id/scrollView"
                        android:fontFamily="sans-serif"
                        android:gravity="top"
                        android:hint="Enter Diary Note...\n\n\n\n"
                        android:text="Dear Parents,"
                        android:textSize="14sp" />


                </RelativeLayout>
            </LinearLayout>
        </LinearLayout>
    </android.support.v7.widget.CardView>
</LinearLayout>

这是我的清单

<activity
            android:name=".DiaryEntry.DiaryEntryTeacherActivity"
            android:label="DiaryEntry"
            android:windowSoftInputMode="adjustResize"
            android:theme="@style/AppTheme.NoActionBar"></activity>

1 个答案:

答案 0 :(得分:0)

您需要使用ScrollView作为;

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/actionbar_title_color"
    android:orientation="vertical">

    <include
        android:id="@+id/include"
        layout="@layout/toolbar" />

    <ScrollView
        android:id="@+id/scroll_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <android.support.v7.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="25dp"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:layout_marginTop="25dp"
            card_view:cardElevation="10sp"
            card_view:cardUseCompatPadding="true">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"

                android:background="#ffffff"
                android:orientation="horizontal">

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_marginTop="10dp"
                    android:layout_weight="1"
                    android:background="@drawable/filebinder" />

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="14"
                    android:orientation="vertical">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="5dp"
                        android:layout_marginRight="10dp"
                        android:orientation="horizontal">


                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="6"
                            android:orientation="vertical">

                            <TextView
                                android:id="@+id/dateDiary"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="10dp"
                                android:fontFamily="sans-serif"
                                android:text="30 July"
                                android:textColor="#03a9f4"
                                android:textSize="20sp" />

                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="1dp"
                                android:layout_marginBottom="10dp"
                                android:background="#03a9f4" />

                        </LinearLayout>

                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="@drawable/diarybookmark" />

                    </LinearLayout>

                    <ScrollView
                        android:id="@+id/scrollView"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="10dp">

                        <EditText
                            android:id="@+id/diaryHeading"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal"
                            android:layout_margin="10dp"
                            android:ems="5"
                            android:fontFamily="sans-serif"
                            android:hint="Diary Heading"
                            android:inputType="textPersonName"
                            android:textAlignment="center"
                            android:textColor="#000000"
                            android:textSize="18sp" />
                    </ScrollView>

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical">


                        <EditText
                            android:id="@+id/diaryTeacherName"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentBottom="true"
                            android:layout_gravity="center"
                            android:fontFamily="sans-serif"
                            android:hint="Teacher\'s Name..."
                            android:textSize="16sp" />


                        <at.markushi.ui.CircleButton
                            android:id="@+id/addDiaryEntry"
                            android:layout_width="74dip"
                            android:layout_height="74dip"
                            android:layout_gravity="right"
                            android:src="@drawable/ic_action_tick"
                            app:cb_color="@color/actionbar_title_color"
                            app:cb_pressedRingWidth="8dip"
                            android:layout_alignParentBottom="true"
                            android:layout_alignParentRight="true"
                            android:layout_alignParentEnd="true" />

                        <EditText
                            android:id="@+id/diaryContent"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_above="@+id/addDiaryEntry"
                            android:layout_alignLeft="@+id/scrollView"
                            android:layout_alignStart="@+id/scrollView"
                            android:layout_alignTop="@+id/scrollView"
                            android:fontFamily="sans-serif"
                            android:gravity="top"
                            android:hint="Enter Diary Note...\n\n\n\n"
                            android:text="Dear Parents,"
                            android:textSize="14sp" />


                    </RelativeLayout>
                </LinearLayout>
            </LinearLayout>
        </android.support.v7.widget.CardView>
    </ScrollView>
</LinearLayout>