java - Android 软键盘打乱了我的布局

标签 java android

我知道有人问了很多关于这个主题的问题,但似乎没有一个对我有用。我有一个线性布局,下面有一个编辑文本和图标,但是当键盘弹出时,它会覆盖图标和一半的编辑文本。

我的 list 文件:

<activity
    android:name="com.social.pages.Post"
    android:windowSoftInputMode="stateVisible|adjustResize"
    android:screenOrientation="portrait" >
</activity>

我的布局文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/feed_bg" >

    <LinearLayout
        android:id="@+id/stories_post_entire"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/story_post"
        android:layout_centerHorizontal="true"
        android:background="@drawable/bg_parent_rounded_corner"
        android:orientation="vertical"
        android:paddingBottom="@dimen/feed_item_padding_top_bottom"
        android:paddingTop="@dimen/feed_item_padding_top_bottom" >

        <!--
             <LinearLayout
            android:id="@+id/stories_post_text"
            android:layout_width="fill_parent"
            android:layout_height="300dp"
            android:layout_marginTop="15dp"
            android:orientation="horizontal"
            android:paddingBottom="@dimen/feed_item_padding_top_bottom"
            android:paddingLeft="@dimen/feed_item_padding_left_right"
            android:paddingRight="@dimen/feed_item_padding_left_right" >
        -->

        <EditText
            android:id="@+id/stories_post_story"
            android:layout_width="fill_parent"
            android:layout_height="300dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/bg_parent_rounded_corner"
            android:ems="10"
            android:gravity="top"
            android:hint="Tell Your Story..."
            android:padding="10dp"
            android:paddingLeft="10dp"
            android:scrollbars="vertical"
            android:typeface="serif" />

        <LinearLayout
            android:id="@+id/stories_post_bar"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginTop="10dp"
            android:paddingLeft="@dimen/feed_item_padding_left_right"
            android:paddingRight="@dimen/feed_item_padding_left_right" >

            <ImageView
                android:id="@+id/stories_post_tag"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scaleType="fitCenter"
                android:src="@drawable/tag" />

            <ImageView
                android:id="@+id/stories_post_take_pic"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="30dp"
                android:scaleType="fitCenter"
                android:src="@drawable/take_pic" />
        </LinearLayout>
    </LinearLayout>

    <!-- </LinearLayout> -->

    <Button
        android:id="@+id/story_post"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="Post" />

</RelativeLayout>

尚未编写 Java 代码。

最佳答案

您将 EditText 元素的高度设置为 300dp,以防止任何内容向上移动。我能够通过将 EditText 和以下 LinearLayout (容纳图像)包装在relativelayout 中来解决此问题。通过这样做,您可以将图像容纳 LinearLayout 设置为alignParentBottom =“true”。我相信这就是您想要的效果。

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/stories_post_entire"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/story_post"
        android:layout_centerHorizontal="true"
        android:orientation="vertical" >

        <!-- ADDITION -->
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">



        <EditText
            android:id="@+id/stories_post_story"
            android:layout_width="fill_parent"
            android:layout_height="300dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="10dp"
            android:ems="10"
            android:gravity="top"
            android:hint="Tell Your Story..."
            android:padding="10dp"
            android:paddingLeft="10dp"
            android:scrollbars="vertical"
            android:typeface="serif" />

        <LinearLayout
            android:id="@+id/stories_post_bar"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_alignParentBottom="true"
            android:layout_marginTop="10dp" >
            <!-- ADDITION    ^^^ alignParentBottom-->

            <ImageView
                android:id="@+id/stories_post_tag"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scaleType="fitCenter"
                android:src="@drawable/osumu_blur"/>

            <ImageView
                android:id="@+id/stories_post_take_pic"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="30dp"
                android:scaleType="fitCenter"
                android:src="@drawable/osumu_blur"/>
        </LinearLayout>

            <!-- ADDITION -->
        </RelativeLayout>
    </LinearLayout>


    <!-- </LinearLayout> -->

    <Button
        android:id="@+id/story_post"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="Post" />

</RelativeLayout>

注意:我用“dummy_image”替换了你的drawable src

关于java - Android 软键盘打乱了我的布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31303944/

相关文章:

java - Android SSL - 不适用于 API 7

android - 无法确定 androidx.appcompat :appcompat:1. 0.2 的 Artifact :没有可用于离线模式的缓存版本

java - OpenJ9 tomcat 不会以高 -Xmx 堆选项启动

java - 从外部服务器在 Thymeleaf 中渲染 html 片段

java - Java 中的 OpenCV 用于图像过滤

java - Android 以编程方式将按钮添加到 ViewGroup

android - 如何在 Android 应用程序中使用 Google 公共(public) API 访问 key ?

android - Toast 消息消失得比它应该的更快

android - 如何创建半椭圆形(弯曲一条线)

Android 以编程方式描边