Android软键按钮隐藏视图的内容 [英] Android Soft-Key-Buttons hide view's content

查看:92
本文介绍了Android软键按钮隐藏视图的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android上带有软键按钮的设备上布局太大感到麻烦:

I'm having troubles with layouts being too large on Devices with Soft-Key-Buttons on Android:

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

Summing up, my question is why a layout, which is configured as "match_parent" has its View-bounds extended to the "real" bottom window bound, instead of just above the Soft-Key-Buttons?

现在是我的特定问题:

尽管在带有软键按钮的任何设备上显示带有视图 layout_alignParentBottom ="true" 的RelativeLayout(在片段中,如果有必要知道的话),视图将显示在软键按钮的后面.

While displaying a RelativeLayout (in a Fragment, if thats necessary to know) with a View layout_alignParentBottom="true" on any Device with Soft-Key-Buttons, the View is displayed "behind" the Soft-Key-Buttons.

没有软键的设备上的视图图像(应该如此)

带有软键按钮的设备上的视图图像(按钮隐藏"软键后面

RelativeLayout看起来像这样:

The RelativeLayout looks like this:

<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做任何事情,因此错误也可能是在片段管理中,所以我也将发布此消息:

As I'm quite new to Android Development and also have not done anything before with Fragments, the error could also be in the fragment-management, so I'm going to post this too:

其中显示了片段的活动是在AndroidManifest中配置的:

The Activity, in which the fragment is shown, is configured in the 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>

所有使用的FrameLayouts的layout_width和layout_height都设置为match_parent.

The used FrameLayouts all have layout_width and layout_height set to match_parent.

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

Right now I'm using kind of a workaround with programmatically checking if the device is showing Soft-Key-Buttons, and if yes, setting the margin of this Button to a higher value:

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上得到了回答).

The problem there is, that the Soft-Key-Buttons have a different height on different devices, so I would have to check the height of the Soft-Key-Buttons too (which is possible and already answered on StackOverflow).

我在这个问题上停留了几周了,非常感谢您的帮助.

I'm stuck at this problem for a few weeks now and would really appreciate any help.

推荐答案

我可以想象三种不同的情况:

I can imagine three different scenarios:

  1. (不太可能)您使用LayoutParams您的Window的标志(例如getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);)和/或主题样式进行操作

  1. (Unlikely)You do something with LayoutParams Flags of your Window(like getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);) and/or Theme's styles

(不太可能.虽然这是我的初稿,但layout_alignParentBottom="true"应该为您处理)屏幕上没有足够的空间.您可以将RelativeLayout包装到 ScrollView (它d要求您将RelativeLayout的高度更改为wrap_content)并查看结果? (如果将match_parent设置为RelativeLayout,这并不意味着它会将所有内容都适合屏幕大小.内容可以轻松地从屏幕上移出,就像您提供的屏幕截图一样.但是,再次使用layout_alignParentBottom="true"可以处理它.

(Unlikely. It was my initial though, but layout_alignParentBottom="true" should handle it for you)You don't have enough space on the screen. Can you wrap your RelativeLayout into a ScrollView(it'd require you to change RelativeLayout's height to wrap_content) and see the result? (If you set match_parent to the RelativeLayout it does not mean it'd fit all content into the screen sizes. Content can easily get out of the screen, like on the screenshot you provided. But again, layout_alignParentBottom="true" handles it.

(最有可能)您在Activity(尤其是android:layout_marginBottom="-XXdp"之类的东西)中托管了Fragment的边距/填充.因此片段可以正确渲染,但活动"会将其移动到屏幕下方.

(Most likely) You have some margins/paddings in the Activity(especially, something like android:layout_marginBottom="-XXdp"), which hosts Fragment. So fragment is rendering correctly, but the Activity moves it below the screen.

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

To speak more precisely, it'd be nice to have @style/AppBaseTheme here, Activity's layout and if you do something suspicious with getWindow() - this piece of code.

让我知道,是否有帮助!

Let me know, if it helps or not!

这篇关于Android软键按钮隐藏视图的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆