Positioning Controls HeaderView (NavigationView)

0

Good afternoon, people.

I'm trying to change a Custom HeaderView, but the controls are not as planned. I used constraint layout and in xml preview everything is correct, but when I start the application, both the emulator and the device the positioning of the header is all wrong. The menus are showing up and they are correct, the problem is with the header itself. (I load it dynamically) but I think it must be a layout problem.

I'm using Fitsystemwindow = true too.

Can you help me?

Follow HeaderLayout code and image

<?xmlversion="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimaryDark"
    android:gravity="bottom"
    android:orientation="vertical"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">


    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/Container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:background="@color/Padrao"
        android:gravity="clip_horizontal"
        android:orientation="vertical"
        android:theme="@style/ThemeOverlay.AppCompat.Dark">

        <ImageView
            android:id="@+id/Header_Menu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:adjustViewBounds="true"
            android:cropToPadding="false"
            android:scaleType="fitXY"
            android:src="@drawable/header_estab_fundo"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />


        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/profile_image2"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_alignParentStart="true"
            android:layout_centerVertical="true"
            android:layout_marginBottom="8dp"
            android:layout_marginTop="8dp"
            android:adjustViewBounds="false"
            android:src="@drawable/pf"
            app:civ_border_color="@color/Padrao"
            app:civ_border_width="2dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.05"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.59000003"></de.hdodenhof.circleimageview.CircleImageView>


        <TextView
            android:id="@+id/txt_usuario_nome"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/profile_image2"
            android:layout_marginStart="64dp"
            android:fontFamily="sans-serif-condensed"
            android:text="LUCAS"
            android:textAllCaps="false"
            android:textColor="@color/NiceButtonEndColor"
            android:textSize="16sp"
            android:textStyle="normal|bold"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.37"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.71000004" />


        <TextView
            android:id="@+id/txt_usuario_token"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/txt_usuario_nome"
            android:layout_alignStart="@+id/txt_usuario_nome"
            android:layout_below="@+id/txt_usuario_nome"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:fontFamily="sans-serif-condensed"
            android:text="4564D"
            android:textAllCaps="false"
            android:textColor="@color/green_900"
            android:textSize="15sp"
            android:textStyle="bold"
            android:visibility="invisible"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.42"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="1.0" />

        <ImageView
            android:id="@+id/ImagemEstabTablet"
            android:layout_width="139dp"
            android:layout_height="90dp"
            android:layout_alignParentEnd="true"
            android:layout_alignTop="@+id/txt_usuario_nome"
            android:layout_marginEnd="24dp"
            android:adjustViewBounds="true"
            android:cropToPadding="true"
            android:src="@color/red_300"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintStart_toStartOf="@+id/Header_Menu"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.6" />

    </android.support.constraint.ConstraintLayout>
</LinearLayout>

When I start the app, it looks like this, remembering that the tablet along with the blue background is a background.

I'm loading the header dynamically

  headerView = new WeakReference<View>(NavigationMenuGeral.inflateHeaderView(R.layout.principal_navegacao_header_estabelecimento)); //principal_navegacao_header
                HeaderEstab = (ImageView) headerView.get().findViewById(R.id.ImagemEstabTablet); //Header_Menu

                HeaderEstab.setImageResource(R.drawable.table_teste);
                navigationView.removeHeaderView(headerView.get());
 NavigationMenuGeral.addHeaderView(headerView.get());

This ImageStabTablet control is an imageview (red) on top of the contents of the tablet to drawable.

Thanks for the help!

    
asked by anonymous 23.07.2018 / 18:04

0 answers