Пользовательское содержимое панели инструментов, обрезанное на некоторых устройствах - PullRequest
0 голосов
/ 04 июля 2018

У меня проблема с пользовательскими панелями инструментов в моем приложении: Example

Кажется, что это происходит только на определенных устройствах, например, у моего личного телефона нет этой проблемы, но проблема есть у эмулятора пикселей на 7.1.1.

Для справки вот код, который я использую.

XML:

<FrameLayout
    android:id="@+id/frame"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/actionBarSize"
        android:layout_marginLeft="0dp"
        android:layout_marginTop="8dp"
        android:layout_weight="1"
        android:background="@drawable/ic_nav"
        android:fitsSystemWindows="true"
        android:paddingLeft="0dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/titleContainer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:minHeight="50dp">

            <ImageView
                android:id="@+id/fwLogo"
                android:layout_width="90dp"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:layout_gravity="left"
                android:layout_marginTop="8dp"
                android:foregroundGravity="left"
                android:gravity="left"
                android:padding="7dp"
                android:scaleType="fitStart"
                app:srcCompat="@drawable/nav_logo" />

                <TextView
                    android:id="@+id/title"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="center"
                    android:foregroundGravity="center"
                    android:gravity="center"
                    android:minHeight="50dp"
                    android:text="Baby And You"
                    android:textAppearance="@style/TextAppearance.AppCompat.Title"
                    android:textColor="@android:color/white" />
        </RelativeLayout>
    </android.support.v7.widget.Toolbar>
</FrameLayout>

Java (хотя, не уверен, имеет ли это отношение или нет):

Toolbar action = findViewById(R.id.toolbar);

setSupportActionBar(action);
setTitle("");

int statusBarHeight = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
    statusBarHeight = getResources().getDimensionPixelSize(resourceId);
}

final TypedArray styledAttributes = getTheme().obtainStyledAttributes(new int[]{android.R.attr.actionBarSize});
int actionSize = (int) styledAttributes.getDimension(0, 0);
styledAttributes.recycle();

int height = statusBarHeight + actionSize;

action.setLayoutParams(new  FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height));

И, наконец, инспектор макетов: Layout inspector

До сих пор я пытался вручную установить высоту, изменить высоту, чтобы обернуть содержимое (как ни странно, оба результата дали правильные пропорции, но текст исчез) и установить minHeight (безрезультатно).

Любая помощь будет принята с благодарностью.

1 Ответ

0 голосов
/ 12 июля 2018

Мне удалось выяснить, что происходит - атрибут android:fitsSystemWindows="true" вызывал эти проблемы. Я просто добавил некоторые ручные отступы и удалил этот атрибут, и все стало отлично работать.

...