键盘出现时布局向上移动

时间:2015-02-10 12:27:50

标签: java android

这是我的xml文件.......我正在尝试构建一个布局,如果键盘出现,则可以滚动布局。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:focusable="true"
android:focusableInTouchMode="true">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    android:fillViewport="true"
    android:focusableInTouchMode="true"
    >
<LinearLayout
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="20dp"
    android:orientation="vertical"
    android:weightSum="10">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".3"
        android:background="@drawable/squareshape"
        android:orientation="horizontal"
        android:weightSum="4">

        <TextView
            android:id="@+id/priority"
            android:layout_width="0dp"
            android:layout_height="32dp"
            android:layout_marginLeft="2dp"
            android:drawableLeft="@drawable/flag"
            android:gravity="center"
            android:text="@string/setpriority"
            android:textColor="@color/actionbarcolor"
            android:textSize="8dp"
            android:layout_weight="1.1"
            android:textStyle="bold" />

        <View
            android:layout_width=".1dp"
            android:layout_height="fill_parent"
            android:layout_marginLeft="2dp"
            android:layout_weight=".01"
            android:background="@android:color/black"></View>

        <TextView
            android:id="@+id/date"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="4dp"
            android:layout_weight="1"
            android:alpha=".5"
            android:drawableLeft="@drawable/date"
            android:gravity="center"
            android:tag="0"
            android:text="@string/setdate"
            android:textColor="@color/actionbarcolor"
            android:textSize="8dp"
            android:textStyle="bold" />
        />

        <View
            android:layout_width=".1dp"
            android:layout_height="fill_parent"
            android:layout_marginLeft="2dp"
            android:layout_weight=".01"
            android:background="@android:color/black"></View>

        <TextView
            android:id="@+id/ime"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="4dp"
            android:alpha=".5"
            android:layout_weight=".5"

            android:drawableLeft="@drawable/time"
            android:gravity="center"
            android:tag="0"
            android:text="@string/settime"
            android:textColor="@color/actionbarcolor"
            android:textSize="8dp"
            android:textStyle="bold" />
        />

        <View
            android:layout_width=".1dp"
            android:layout_height="fill_parent"
            android:layout_marginLeft="2dp"
            android:layout_weight=".01"
            android:background="@android:color/black"></View>

        <TextView
            android:id="@+id/location"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:alpha=".5"

            android:drawableLeft="@drawable/location"
            android:gravity="center"
            android:tag="0"
            android:text="@string/setlocation"
            android:textColor="@color/actionbarcolor"
            android:textSize="8dp"
            android:textStyle="bold"
            android:layout_weight="1.07" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:weightSum="2"
        android:layout_weight="6"
        android:orientation="horizontal"
        android:background="@drawable/squareshape">

        <EditText
            android:id="@+id/newnote_edittext_note"
            android:layout_width="0dp"
            android:layout_weight="1.5"
            android:layout_height="match_parent"
            android:background="@drawable/squareshape"

            android:gravity="top" />
        <ListView
            android:id="@+id/listview_list"
            android:layout_width="0dp"
            android:layout_weight=".5"

            android:layout_height="fill_parent"></ListView>
    </LinearLayout>

    <LinearLayout

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="25dp"
        android:layout_weight=".5"
        android:weightSum="3">

        <ImageView
            android:id="@+id/imageview_addphoto"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"

            android:src="@drawable/picturebuttonnor" />

        <ImageView
            android:id="@+id/imageview1_video"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"

            android:src="@drawable/videobuttonnor" />

        <ImageView
            android:id="@+id/imageview"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:contentDescription="newnote_imageview_audio"
            android:src="@drawable/audiobuttonnor" />
    </LinearLayout>

</LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:isScrollContainer="false"
        android:layout_alignParentBottom="true"
        >
    <include
        android:id="@+id/include"
        layout="@layout/bottomlayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"></include>
    </LinearLayout>
    </RelativeLayout>

   </ScrollView>

当键盘出现时,布局正在向上移动。所以整个布局都没有滚动。如何停止此操作?请帮助......

1 个答案:

答案 0 :(得分:0)

尝试在AndroidManifest.xml中定义以下属性

android:windowSoftInputMode="stateVisible|adjustResize"

如果您的用户界面包含用户在执行文字输入后或执行文字输入时可能需要立即访问的控件,则指定“adjustResize”非常重要。更多信息请检查this