android - 键盘启动时如何设置编辑文本?

标签 android xml android-softkeyboard

我有一个 Activity ,其中有带 fragment 的谷歌地图,在底部有一个编辑框。因此,当我单击编辑框时,会显示软键盘。但是我隐藏了我的编辑框。那么我怎样才能让我的编辑框位于软键盘的顶部。请帮助我。这是我的代码。:-

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/grey_bg"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="524dp"
    android:orientation="vertical" >

    <!-- Header -->

    <LinearLayout
        android:id="@+id/relativeLayoutheader"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="0.7"
        android:background="@drawable/header"
        android:orientation="horizontal" >

        <LinearLayout
            android:id="@+id/backLinearLayout"
            android:layout_width="0dip"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:padding="10dp" >

            <ImageView
                android:id="@+id/imgBack"
                android:layout_width="30dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:src="@drawable/back" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="match_parent"
            android:layout_weight="4"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/txtLocationName"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center"
                android:text="Kommentare"
                android:textColor="@android:color/white"
                android:textSize="16sp" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/deleteLikeLinearLayout"
            android:layout_width="0dip"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/imgTrash"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:src="@drawable/trash"
                android:visibility="gone" />

            <ImageView
                android:id="@+id/imgLike"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:src="@drawable/like"
                android:visibility="gone" />

            <ImageView
                android:id="@+id/imgLiked"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:src="@drawable/like_button_focus"
                android:visibility="gone" />
        </LinearLayout>
    </LinearLayout>

    <!-- Body Part -->

    <LinearLayout
        android:id="@+id/bodyLinearLayout"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="9"
        android:orientation="vertical"
        android:weightSum="10" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="3"
            android:orientation="horizontal" >

            <LinearLayout
                android:id="@+id/imgPostLinearLayout"
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:orientation="horizontal" >

                <ImageView
                    android:id="@+id/imgPost"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:scaleType="fitXY" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/mapFragmentLayout"
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:orientation="vertical" >

                <ImageView
                    android:id="@+id/imgMap"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:scaleType="fitXY" />

                <!--
                 <fragment
                android:id="@+id/map"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                class="com.google.android.gms.maps.SupportMapFragment" />

                -->
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:id="@+id/listRelatedCommentLinearLayout"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="5.7"
            android:orientation="vertical" >

            <fragment
                android:id="@+id/frag_list"
                android:name="com.handmark.pulltorefresh.extras.listfragment.PullToRefreshListFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentTop="true" />
            <!--
        <ListView
            android:id="@+id/listRelatedComment"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
        </ListView>

            -->

        </LinearLayout>

        <!-- footer -->

        <LinearLayout
            android:id="@+id/footerLinearLayout"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@drawable/bottom_bar"
            android:orientation="horizontal" >

            <LinearLayout
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:layout_weight="3"
                android:orientation="horizontal"
                android:padding="10dp" >

                <EditText
                    android:id="@+id/edtRelatedComments"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:background="@drawable/bottom_search"
                    android:hint="Kommentieren…"
                    android:maxLength="140"
                    android:paddingLeft="10dp"
                    android:textSize="13sp" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/sendButtonLinearLayout"
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="1.1" >

                <Button
                    android:id="@+id/btnAbsenden"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:background="@android:color/transparent"
                    android:gravity="center"
                    android:text="Absenden"
                    android:textColor="@android:color/white"
                    android:textSize="14sp" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

在我的 list 中我尝试过

 android:windowSoftInputMode="adjustPan"

enter image description here

enter image description here

最佳答案

尝试添加

android:windowSoftInputMode="adjustResize"

关于 Activity 。这是我的代码 fragment 。

  <activity
   android:label="@string/app_name"
   android:name=".youractivity" android:windowSoftInputMode="adjustResize">

关于android - 键盘启动时如何设置编辑文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25175357/

相关文章:

android - AlignParentBottom 按钮与 Scroll/Focus 上的 Textview 重叠

android - Android 中对 EditField 的表情符号键盘支持

android - 如何在 Android 日期选择器中禁用过去和 future 的月份?

java - 当一个类实现一个监听器接口(interface)来监听扩展 BroadcastReceiver 的类中记录的变化时,没有任何反应

iphone - KissXML 和 GData 已弃用?

.net - 计算具有 2 种子节点类型的父节点 - 特别是 1 "boy"节点和 1 "girl"节点

xml - 错误 : The prefix "xsi" for attribute "xsi:schemaLocation" is not bound

java - 如何将 View 锚定到 Android 软键盘

android - 为什么我无法在 VS 2015 中安装 google play services maps (Android)?

php - 尝试在 Windows Server 2012 x64 上注册 COM dll 时注册失败