【发布时间】:2016-04-07 06:22:22
【问题描述】:
我在 Android 上带有软键按钮的设备上的布局过大时遇到了问题:
总结一下,我的问题是为什么配置为 "match_parent" 的布局将其视图边界扩展到“真实”底部窗口边界,而不是在软键按钮上方?
现在是我的具体问题:
在任何带有软键按钮的设备上显示具有视图 layout_alignParentBottom="true" 的 RelativeLayout(在片段中,如果有必要知道的话),视图显示在软键按钮的“后面”。
Image of the View on a Device without Soft-Key-Buttons (as it should be)
Image of the View on a Device with Soft-Key-Buttons (the Button is "hiding" behind the Soft-Keys)
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 上回答了)。
我已经被这个问题困扰了几个星期,非常感谢任何帮助。
【问题讨论】:
标签: android android-layout android-fragments softkeys