4

我在 Android 上带有软键按钮的设备上的布局太大时遇到问题:

总而言之,我的问题是为什么配置为“match_parent”的布局将其视图边界扩展到“真实”底部窗口​​边界,而不是在软键按钮上方?

现在到我的具体问题:

在任何具有软键按钮的设备上显示具有视图layout_alignParentBottom="true"的 RelativeLayout(在片段中,如果有必要知道的话)时,视图显示在软键按钮“后面”。

没有软键按钮的设备上的视图图像(应该是)

带有软键按钮的设备上的视图图像(按钮“隐藏”在软键后面)

相对布局如下所示:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg2">

    <LinearLayout
        android:layout_marginTop="@dimen/settings_container_margin_top"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:orientation="vertical">

        <!-- Some views -->

    </LinearLayout>

    <at.eventdrivers.android.ui.MenuButton
        android:layout_width="250dp"
        android:layout_height="50dp"
        android:layout_gravity="center_horizontal"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        custom:btnText="@string/..." />

</RelativeLayout>

由于我对 Android 开发还很陌生,并且之前也没有对 Fragments 做过任何事情,所以错误也可能出现在 Fragment 管理中,所以我也将发布这个:

显示片段的 Activity 在 AndroidManifest 中配置:

<activity
    android:name=".slidingmenu.SlidingHomeActivity"
    android:label="@string/app_name"
    android:logo="@mipmap/ic_launcher"
    android:theme="@style/AppBaseTheme"
    android:windowSoftInputMode="adjustResize"
    android:screenOrientation="portrait" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

使用的 FrameLayout 都将 layout_width 和 layout_height 设置为 match_parent。

现在我正在使用一种解决方法,以编程方式检查设备是否显示软键按钮,如果是,则将此按钮的边距设置为更高的值:

public static boolean hasSoftKeys(Context c) {
    if(Build.VERSION.SDK_INT <= 10 || (Build.VERSION.SDK_INT >= 14 &&
            ViewConfiguration.get(c).hasPermanentMenuKey())) {
        //menu key is present
        return false;
    } else {
        //No menu key
        return true;
    }
}

问题在于,软键按钮在不同设备上的高度不同,所以我也必须检查软键按钮的高度(这是可能的,并且已经在 StackOverflow 上回答了)。

我已经被这个问题困了几个星期了,非常感谢任何帮助。

4

2 回答 2

4

这个对我有用,只需将其添加到您的 v21/styles.xml

<item name="android:windowDrawsSystemBarBackgrounds">false</item>
于 2017-09-09T21:45:32.267 回答
2

我可以想象三种不同的场景:

  1. (不太可能)您使用(like ) 和/或 Theme 样式的LayoutParams标志做某事WindowgetWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

  2. (不太可能。虽然这是我最初的,但layout_alignParentBottom="true"应该为您处理)您的屏幕上没有足够的空间。你能把你的包装RelativeLayout成 a ScrollView(它需要你把RelativeLayout' 的高度改为wrap_content)并查看结果吗?(如果您设置match_parentRelativeLayout它并不意味着它会将所有内容都放入屏幕尺寸。内容可以很容易地离开屏幕,就像您提供的屏幕截图一样。但同样,layout_alignParentBottom="true"处理它。

  3. Activity(很可能)您在(尤其是类似的)中有一些边距/填充android:layout_marginBottom="-XXdp",其中托管Fragment. 所以片段正确呈现,但活动将其移动到屏幕下方。

更准确地说,最好在@style/AppBaseTheme这里有 Activity 的布局以及如果你对getWindow()- 这段代码做了一些可疑的事情。

让我知道,如果它有帮助或没有!

于 2016-01-03T22:51:41.557 回答