我在安卓系统上使用软键按钮的设备上遇到布局过大的问题:
总之,我的问题是,为什么配置为“match_parent”的布局的视图范围扩展到“real”底部窗口范围,而不是仅仅在软键按钮上方?
现在谈谈我的具体问题:
在任何带有软键按钮的设备上显示视图布局为“alignparentbottom=”true“的相对延迟(在片段中,如果需要知道的话),视图显示在软键按钮的“后面”。
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
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 management中,所以我也将发布以下内容:
显示片段的活动在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>
使用的框架布局都将布局宽度和布局高度设置为与父级匹配。
现在我正在使用一种变通方法,通过编程检查设备是否显示软键按钮,如果是,则将此按钮的边距设置为更大的值:
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上得到了回答)。
我已经在这个问题上困了几个星期了,非常感谢你的帮助。
最佳答案
我可以想象三种不同的情况:
(不太可能)使用LayoutParams
标记和/或主题的样式
(不太可能。不过,这是我的初始设置,但Window
应该为您处理)屏幕上没有足够的空间。你能把你的getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
包装成一个layout_alignParentBottom="true"
(它要求你把RelativeLayout
的高度改成ScrollView
)并看到结果吗?(如果将RelativeLayout
设置为wrap_content
,并不意味着它可以将所有内容都适合屏幕大小。内容很容易从屏幕上消失,就像你提供的截图一样。但同样,match_parent
会处理它。
(很可能)您在RelativeLayout
中有一些边距/填充(特别是像layout_alignParentBottom="true"
这样的),它承载Activity
。因此片段渲染正确,但活动将其移动到屏幕下方。
更准确地说,这里有android:layout_marginBottom="-XXdp"
这个活动的布局,如果你对Fragment
做了什么可疑的事情,那就太好了-这段代码。
让我知道,如果它有帮助或没有!