Есть ли способ проверить кнопку обзора? - PullRequest
0 голосов
/ 04 мая 2018

Я разрабатываю приложение, в котором на начальном экране есть левый ящик. Выдвижной ящик идеально подходит для большинства устройств, но на некоторых устройствах он закрывается независимо от того, есть ли на экране кнопка обзора (телефон без физической кнопки, используется экранная кнопка) или она проглочена под нижней частью экрана (в основном это происходит на Xiaomi, и да, я пробовал на 5 телефонах Xiaomi). Это также происходит на эмуляторе от Android-студии. Вопрос в том, может ли приложение знать, есть ли на телефоне кнопка обзора, поэтому приложение может быть разработано так, чтобы размещать макет поверх него (не покрывая его). Или есть другой способ, более простой и эффективный?

Вот код макета:

<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 голосов
/ 04 мая 2018

Это распространенная проблема. Размещение списка (или более) внутри прокрутки не очень хорошо. Если у вас есть конечное количество элементов, я предлагаю вам создать свой вид программно (используйте addView).

Однако, если вы не хотите изменять свой код, прочитайте это: представление списка внутри scrollview .

По сути, вам нужно вычислить реальную высоту списка для каждого элемента ( getMeasuredHeight ) после notifyDataSetChanged . Это должно исправить вашу проблему.

0 голосов
/ 04 мая 2018

Чтобы предотвратить наложение с помощью нижней программной панели навигации, добавьте это в файл styles.xml в каталоге values-v21 (если dir не существует, создайте его и скопируйте тот же файл styles.xml из значения):

<item name="android:windowDrawsSystemBarBackgrounds">false</item>

Как, например, -

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

</style>
0 голосов
/ 04 мая 2018

Извините, если я не понимаю вашего вопроса.

Я не вижу в вашем 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

См. Руководство Googles для получения более подробной информации. Надеюсь, это поможет вам.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...