有没有办法检查概览按钮?

时间:2018-05-04 09:38:20

标签: java android android-layout

我正在开发一个应用程序,主屏幕上有一个左抽屉。抽屉完全适合大多数设备,但在某些设备上,无论屏幕是否有概览按钮(没有物理按钮的电话,使用屏幕按钮)还是屏幕底部吞下的抽屉(主要发生在小米上,是的,我已经试过了5个xiaomi手机)。这也发生在android studio的模拟器上。问题是,应用程序可以知道手机上是否有概述按钮,因此可以开发应用程序以将布局放在顶部(不覆盖)它。还是有另一种方式,更简单有效?

这是布局代码:

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
    android:id="@+id/drawer_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
</LinearLayout>
<!-- *********** NAVIGATION DRAWER *********** -->

<LinearLayout
    android:id="@+id/left_drawer"
    android:layout_width="@dimen/drawer_width"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    android:background="@color/drawerColor"
    android:fitsSystemWindows="true">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:paddingLeft="@dimen/drawer_user_padding_left"
        android:paddingBottom="@dimen/drawer_user_padding_bottom"
        android:paddingTop="@dimen/drawer_user_padding_top_newest"
        android:orientation="vertical" >
        <TextView
            android:id="@+id/referal_ID"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="@dimen/nav_fontsize"
            android:textColor="@color/orange"
            android:textStyle="bold"
            android:text="\nReferal ID: " />

        <TextView
            android:id="@+id/profile_no"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="@dimen/content_fontsize"
            android:textColor="@color/orange"
            android:textStyle="bold"
            android:text="000" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/userdata_wrapper"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/theme"
        android:paddingLeft="@dimen/drawer_user_padding_left"
        android:paddingTop="@dimen/drawer_separator_margin_top"
        android:paddingBottom="@dimen/drawer_user_padding_bottom"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/profile_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="@dimen/content_fontsize"
            android:textColor="@color/white"
            android:textStyle="bold"
            android:text="Name" />

        <TextView
            android:id="@+id/profile_email"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="@dimen/content_fontsize"
            android:textColor="@color/white"
            android:text="email@email.com" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/icon_point"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:adjustViewBounds="true"
                android:background="@android:color/transparent"
                android:src="@drawable/magno_coin"/>

            <TextView
                android:id="@+id/profile_credit"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:textSize="@dimen/content_fontsize"
                android:textColor="@color/white"
                android:textStyle="bold"
                android:text="0"/>

        </LinearLayout>

    </LinearLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:scrollbars="none">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <ListView
                android:id="@+id/upper_nav"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/drawer_upper_nav_margin"
                android:isScrollContainer="false"
                android:scrollbars="none" >

            </ListView>

            <View
                android:id="@+id/upper_separator"
                android:layout_width="fill_parent"
                android:layout_height="@dimen/drawer_separator_height"
                android:layout_marginTop="@dimen/drawer_separator_margin_top"
                android:layout_marginBottom="@dimen/drawer_separator_margin_bottom"
                android:background="@color/contentColor"/>

            <ListView
                android:id="@+id/middle_nav"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:isScrollContainer="false"
                android:scrollbars="none">
            </ListView>

            <View
                android:id="@+id/middle_separator"
                android:layout_width="fill_parent"
                android:layout_height="@dimen/drawer_separator_height"
                android:layout_marginTop="@dimen/drawer_separator_margin_top"
                android:layout_marginBottom="@dimen/drawer_separator_margin_bottom"
                android:background="@color/contentColor"/>

            <ListView
                android:id="@+id/lower_nav"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:isScrollContainer="false"
                android:scrollbars="none">
            </ListView>

            <View
                android:id="@+id/lower_separator"
                android:layout_width="fill_parent"
                android:layout_height="@dimen/drawer_separator_height"
                android:layout_marginTop="@dimen/drawer_separator_margin_top"
                android:layout_marginBottom="@dimen/drawer_separator_margin_bottom"
                android:background="@color/contentColor"/>

            <ListView
                android:id="@+id/bottom_nav"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:isScrollContainer="false"
                android:layout_marginBottom="@dimen/item_margin"
                android:scrollbars="none">
            </ListView>
        </LinearLayout>

    </ScrollView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <View
            android:layout_width="match_parent"
            android:layout_height="@dimen/drawer_separator_height"
            android:background="@color/theme"/>

        <TextView
            android:id="@+id/current_version"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="bottom|right"
            android:layout_alignParentBottom="true"
            android:layout_marginTop="@dimen/item_space_margin"
            android:layout_marginBottom="@dimen/item_space_margin"
            android:layout_marginRight="@dimen/version_margin"
            android:textSize="@dimen/smaller_fontsize"
            android:textColor="@color/black"
            android:text="ver 1.0.0"/>

    </LinearLayout>
</LinearLayout></android.support.v4.widget.DrawerLayout>

On the picture i scrolled down until cant be scrolled anymore

在图片上我向下滚动,直到不能再滚动

3 个答案:

答案 0 :(得分:1)

抱歉,如果我不明白你的问题。

我没有在你的xml android.support.design.widget.NavigationView中看到 - 它是抽屉内容的容器。您需要将implementation 'com.android.support:design:27.1.1'添加到您的应用依赖项才能使用NavigationView。

如果您想为抽屉做静态标题,则会有app:headerLayout="@layout/nav_header"属性,其中nav_header是您的标题布局。

对于其他项目,有app:menu="@menu/drawer_view属性,其中drawer_view是您的抽屉菜单。在此菜单中,您可以根据需要放置任意数量的项目,如果需要,它们将可滚动。您也可以根据需要进行设计,并且可以在NavigationView.OnNavigationItemSelectedListener

中轻松处理

有关详细信息,请参阅此Google帐户guide。希望它会对你有所帮助。

答案 1 :(得分:1)

这是一个常见问题。在scrollview中放置listview(或更多)并不好。如果您的元素数量有限,我建议您以编程方式构建视图(使用addView)。

但是,如果您不想更改代码,请阅读:list view inside scrollview

基本上,您需要在 notifyDataSetChanged 之后计算每个项目( getMeasuredHeight )的列表视图的实际高度。这应该可以解决你的问题。

答案 2 :(得分:1)

要防止Bottom Soft NavigationBar重叠,请将其添加到values-v21目录中的styles.xml中(如果目录不存在,请创建一个并从值复制相同的styles.xml文件):

<item name="android:windowDrawsSystemBarBackgrounds">false</item>
像这样的例如 -

<style name="Theme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:windowDrawsSystemBarBackgrounds">false</item>
    .....
    .....

</style>
相关问题