我面临一个烦人的问题几个小时。
我有一个相对布局,其徽标具有一个 marginTop 和一个与底部对齐的按钮,该按钮具有一个 marginBottom。在这两个视图之间,还有一些其他的视图,居中。
打开键盘时会出现此问题。我想要发生的是提升一切。实际发生的情况是按钮被抬起,徽标保持在固定位置,其他视图被挤压在中间(在小型设备上它们甚至消失)。
我知道如果所有其他视图都相对于彼此,从徽标或按钮开始(绝不是两者!),问题就可以解决。但在这种情况下,徽标和按钮将不在所需的位置。
任何想法都非常感谢。
我面临一个烦人的问题几个小时。
我有一个相对布局,其徽标具有一个 marginTop 和一个与底部对齐的按钮,该按钮具有一个 marginBottom。在这两个视图之间,还有一些其他的视图,居中。
打开键盘时会出现此问题。我想要发生的是提升一切。实际发生的情况是按钮被抬起,徽标保持在固定位置,其他视图被挤压在中间(在小型设备上它们甚至消失)。
我知道如果所有其他视图都相对于彼此,从徽标或按钮开始(绝不是两者!),问题就可以解决。但在这种情况下,徽标和按钮将不在所需的位置。
任何想法都非常感谢。
我试过你在这里描述的:
不要忘记 FILLVIEWPORT = true。对于滚动视图
这就是我想出的,并且效果很好:
<?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>