如何查找菜单高度

时间:2017-07-02 13:05:05

标签: android xml

我想创建固定的导航布局,但是当我旋转设备时出现问题,此布局的margin-top比它必须更多,所以问题 - 如何才能找到这个深蓝色标题的高度(将其用作保证金),或者可能有另一种方式

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_marginTop="55dp"
    android:layout_height="80dp"
    android:background="@drawable/panel_border"
    android:layout_alignParentTop="true">

enter image description here

2 个答案:

答案 0 :(得分:0)

让android支持库为你做。喜欢这个

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 <! -- Your View -->

        <RelativeLayout
        android:layout_width="match_parent"

        android:layout_height="wrap_content"
        android:background="@drawable/panel_border"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
  <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|enterAlways">
 </android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

看看this

答案 1 :(得分:0)

如果我是你,我会接受这个:

android:layout_marginTop="?attr/actionBarSize"

此属性表示ActionBar / Toolbar的正确高度  不同API的Toolbars高度可能不同,这就是您应该使用?android:attr?attr(使用支持库时)的原因。  ?表示它来自内部Android资源。