【问题标题】:Soft keyboard issure软键盘问题
【发布时间】:2015-12-18 01:50:42
【问题描述】:

我正在尝试在软键盘加载时调整我的屏幕。正常画面是这样的。

但是,当用户单击 EditText 时,视图会中断并显示如下。在我的活动清单中,我添加了以下 android:windowSoftInputMode="adjustResize"

我想要发生的是,底部的两个按钮都会出现,并且当用户单击 EditText 时,整个 Edittext 都是可见的而不会被剪切。

编辑:将以下行添加到我的活动 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); 使我的视图看起来像这样。但我仍然希望我的两个按钮出现在 EditText 的底部

底部 EditText 和按钮的 XML

 <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1.6  "
        android:background="#FFFFFF"
        android:orientation="vertical">

        <LinearLayout

            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1">

            <EditText

                android:hint="Enter your Message"
                android:ems="10"
                android:id="@+id/messageET"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1">

                <RelativeLayout
                    android:background="@drawable/lightrectangle"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="2.5">

                    <ImageButton
                        android:id="@+id/addimgbtn"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:background="#f6f6f6"
                        android:paddingLeft="10dp"
                        android:src="@mipmap/blueadd" />

                    <TextView
                        android:paddingLeft="10dp"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:text="Add an image"
                        android:id="@+id/textView4"
                        android:layout_centerVertical="true"
                        android:layout_toRightOf="@+id/addimgbtn"
                       />
                </RelativeLayout>


                <RelativeLayout
                    android:background="@drawable/lightrectangle"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="2.5">

                    <ImageButton
                        android:id="@+id/sendbtn"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:paddingLeft="10dp"
                        android:layout_weight="2.5"
                        android:background="#f6f6f6"
                        android:src="@mipmap/bluesend" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:text="Send Message"
                        android:id="@+id/sendmsgTV"
                        android:layout_centerVertical="true"
                        android:layout_toRightOf="@+id/sendbtn"
                        android:paddingLeft="10dp"
                        />
                </RelativeLayout>
            </LinearLayout>
    </LinearLayout>

【问题讨论】:

  • 您将不得不发布至少一个简化版的布局。调整大小是您想要的,但需要有一个实际上可以调整大小的视图。
  • @GabeSechan 我需要调整什么大小?
  • 该中心列表需要可收缩。
  • 一个简单的例子是,如果这一切都是我的亲戚,按钮与专利底部对齐,文本视图上方的列表并设置为填充专利。这会起作用(该列表将占用所有可用空间
  • @GabeSechan 检查编辑后的回复

标签: android android-softkeyboard window-resize


【解决方案1】:

在滚动视图中添加字段或布局,这将自动调整您的布局。你可以滚动你的布局,它在所有屏幕上都是自动调整的。

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.6  "
android:background="#FFFFFF"
android:orientation="vertical" >

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" >

        <EditText
            android:id="@+id/messageET"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:ems="10"
            android:hint="Enter your Message" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="2.5"
            android:background="@drawable/lightrectangle" >

            <ImageButton
                android:id="@+id/addimgbtn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:background="#f6f6f6"
                android:paddingLeft="10dp"
                android:src="@mipmap/blueadd" />

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@+id/addimgbtn"
                android:paddingLeft="10dp"
                android:text="Add an image"
                android:textAppearance="?android:attr/textAppearanceSmall" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="2.5"
            android:background="@drawable/lightrectangle" >

            <ImageButton
                android:id="@+id/sendbtn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_weight="2.5"
                android:background="#f6f6f6"
                android:paddingLeft="10dp"
                android:src="@mipmap/bluesend" />

            <TextView
                android:id="@+id/sendmsgTV"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@+id/sendbtn"
                android:paddingLeft="10dp"
                android:text="Send Message"
                android:textAppearance="?android:attr/textAppearanceSmall" />
        </RelativeLayout>
    </LinearLayout>
</ScrollView>

【讨论】:

    猜你喜欢
    • 2011-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-16
    • 2012-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多