打开键盘后布局减少

问题描述 投票:0回答:1

layout samples您好。我有一些问题。

我有一个布局,它由EditText和RelativeLayout组成,它们具有固定的高度%,还有GridView,它们位于它们之间匹配父(匹配约束)。

一切都很顺利,而没有键盘。键盘出现时%不从整个屏幕计算,而是从没有键盘的部分计算。我需要在键盘的外观上更改GridView的大小,并且以%计算的其余元素不会更改。

在此之前,我以像素为单位计算屏幕高度的百分比,并以编程方式设置它。但我想在布局层面上做这件事。真的是这样做是不可能的。

我尝试使用带有guidline layout_constraintGuide_percent的ConstraintLayout和像根视图一样的PercentageRelativeLayout - 无用。在清单中也更改活动windowSoftInputMode。

布局xml

<android.support.constraint.ConstraintLayout
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:fitsSystemWindows="true"
tools:context=".activity.ActivityAllApps">

<RelativeLayout
    android:id="@+id/rlTabTitleAllApps"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_constraintBottom_toTopOf="@+id/qlTabTitle"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:background="@drawable/background_action_bar9">

    <include layout="@layout/include_sortings"/>

    <Button
        android:id="@+id/bTest"
        android:layout_width="35dp"
        android:layout_height="35dp"
        android:layout_alignBottom="@+id/ibSettingsMenu"
        android:layout_marginStart="36dp"
        android:layout_toEndOf="@+id/rlSorts"
        android:onClick="onTestButton2Click"
        android:text="T"/>

    <ImageButton
        android:id="@+id/ibSettingsMenu"
        style="@style/MenuButtonSettings"
        android:layout_alignParentEnd="true"
        android:layout_centerVertical="true"
        android:onClick="onSettingsMenuClick"
        tools:background="@drawable/settings_menu_button"/>

</RelativeLayout>

<GridView
    android:id="@+id/gvAllApps"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:horizontalSpacing="2dp"
    android:numColumns="4"
    android:overScrollMode="never"
    android:padding="2dp"
    android:verticalSpacing="2dp"
    app:layout_constraintBottom_toTopOf="@+id/etSearch"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/rlTabTitleAllApps"/>

<EditText
    android:id="@+id/etSearch"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:hint="@string/search_app"
    android:textAlignment="center"
    android:textCursorDrawable="@drawable/cursor_edit_text9"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="@+id/qlSearch"
    tools:background="@drawable/search_app_background9"/>

<android.support.constraint.Guideline
    android:id="@+id/qlTabTitle"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    app:layout_constraintGuide_percent="@dimen/constraint_tab_top"/>

<android.support.constraint.Guideline
    android:id="@+id/qlSearch"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    app:layout_constraintGuide_percent="@dimen/constraint_all_search"/>

</android.support.constraint.ConstraintLayout>

对不起我的英语不好。

android android-layout percentage android-constraintlayout
1个回答
0
投票

获得所需内容的最简单方法是将页眉和页脚放在自定义视图中。在这些自定义视图中,覆盖它们的onMeasure以查看屏幕的大小并从中计算它们的高度。然后使用如下所示的布局:

<RelativeLayout>
    <CustomHeaderView layout_alignParentTop="true"/>
    <FrameLayout layout_below="customHeaderView"  layout_above="customFooterView">
        //Your center here
    </FrameLayout>
    <CustomFooterView layout_alignParentBottom="true"/>
</RelativeLayout>

这将为您提供固定尺寸的顶部和底部,中心部分尽可能适合内部(我假设您在那里有一个滚动视图。

在softInputMode调整大小时使用它。但是没有简单的方法来获得你想要的行为而没有像这样的技巧,Android本身并不支持它。

© www.soinside.com 2019 - 2024. All rights reserved.