具有固定边距的Android adjustResize

时间:2017-01-05 12:35:35

标签: android keyboard margin window-soft-input-mode

我在几个小时内面临一个恼人的问题。

我有一个带有徽标的相对布局,该徽标有一个marginTop和一个与底部对齐的按钮,它有一个marginBottom。在这两种观点之间还有一些其他观点,以中心为主。

enter image description here

键盘打开时出现问题。我想要发生的是提升一切。发生的事情是按钮被抬起,徽标停留在固定位置,其他视图被挤压在中间(在小型设备上甚至消失)。

enter image description here

我知道如果所有其他视图彼此相对,可以解决问题,从徽标或按钮开始(从不同时!)。但在这种情况下,徽标和按钮将不在所需的位置。

非常感谢任何想法。

1 个答案:

答案 0 :(得分:0)

我尝试了你在这里描述的内容:

不要忘记FILLVIEWPORT = true。对于scrollview

这是我想出来的,它完美无缺:

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

    <RelativeLayout
        android:id="@+id/activity_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="be.vanlooverenkoen.testing.MainActivity">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="150dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:scaleType="fitXY"
            app:srcCompat="@mipmap/ic_launcher" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/button"
            android:layout_below="@+id/imageView"
            android:background="@color/colorAccent" />

        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:text="Button" />
    </RelativeLayout>
</ScrollView>
相关问题