How to prevent ConstraintLayout from occupying the entire screen

0

I have created a horizontal menu in the main Activity , where one of your items has a button that calls a Activity that contains a ConstraintLayout p>

But when I enter that Activity it occupies the whole screen hiding the menu.

This is the xml code

activity_main.xml

<?xml version="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="match_parent"
android:orientation="vertical"
tools:context="com.SoCu.CirDocu.MainActivity">

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

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

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?android:actionBarSize"
            android:background="@color/colorPrimary"
            android:elevation="4dp"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/AppTheme.FondoMenu"
            app:theme="@style/ThemeOverlay.AppCompat.Dark"
            app:titleTextColor="@android:color/white">

            <TextView
                android:id="@+id/texto_toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="clip_vertical"
                android:text= "@string/titulo_app"
                android:textSize="20sp" />

        </android.support.v7.widget.Toolbar>

         <com.SoCu.Docu_AD.custom_views.HorizontalScrollMenuView
            android:id="@+id/horizontal_menu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:backgroundMenuColor="#0099cc"
            app:backgroundNotifications="@color/colorAccent"
            app:icon_height="30dp"
            app:icon_width="30dp"
            app:item_backgroundColor="@color/colorPrimary"
            app:item_colorSelected="#ffffff"
            app:item_textColor="#ffffff" />

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <TextView
            android:id="@+id/ver_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>

    <ExpandableListView
        android:id="@+id/explist_slidermenu"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#FFFFFF"
        android:choiceMode="singleChoice"
        android:divider="@color/Gris1"
        android:dividerHeight="0.5dp"
        android:listSelector="#bfbfbf" >
    </ExpandableListView>

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

<FrameLayout
    android:id="@+id/frame_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" />

</LinearLayout>

apuntes.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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="match_parent"
android:minHeight="180dp"
tools:context="com.SoCu.CirDocu.Apuntes"
tools:layout_editor_absoluteY="25dp">

<EditText
    android:id="@+id/txt_nombre"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="35dp"
    android:layout_marginStart="35dp"
    android:layout_marginTop="176dp"
    android:ems="10"
    android:hint="@string/txt_nombre"
    android:inputType="textPersonName"
    app:layout_constraintBottom_toTopOf="@+id/txt_contenido"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<EditText
    android:id="@+id/txt_contenido"
    android:layout_width="360dp"
    android:layout_height="320dp"
    android:layout_marginEnd="24dp"
    android:layout_marginStart="24dp"
    android:layout_marginTop="8dp"
    android:background="#1634F7"
    android:ems="10"
    android:gravity="top"
    android:inputType="textMultiLine"
    android:textColor="#FFFFFF"
    app:layout_constraintBottom_toTopOf="@+id/button"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/txt_nombre" />

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="16dp"
    android:layout_marginStart="32dp"
    android:onClick="Guardar"
    android:text="@string/boton_Guardar"
    android:textSize="18sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toStartOf="@+id/button2"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/txt_contenido" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="32dp"
    android:layout_marginStart="16dp"
    android:layout_marginTop="16dp"
    android:onClick="Consultar"
    android:text="@string/boton_Consultar"
    android:textSize="18sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="1.0"
    app:layout_constraintStart_toEndOf="@+id/button"
    app:layout_constraintTop_toBottomOf="@+id/txt_contenido" />

</android.support.constraint.ConstraintLayout>

How can I leave that activity below the menus so they can be seen?

Thanks.

    
asked by SoCu 09.09.2018 в 21:01
source

1 answer

1

This would be the activity_main.xml is a DrawerLayout, it contains the left side menu inside a NavigationView, inside it we will put an app_bar_main:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:openDrawer="start">

        <include
            layout="@layout/app_bar_main"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <android.support.design.widget.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            app:headerLayout="@layout/nav_header_main"
            app:menu="@menu/activity_main_drawer" />

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

This would be the app_bar_main.xml and within this layout we include the apuntes.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    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="match_parent"
    tools:context=".activities.EventoActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" >
                <HorizontalScrollView
                    android:id="@+id/horizontal_menu"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                </HorizontalScrollView>
        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/apuntes" />

</android.support.design.widget.CoordinatorLayout>

In layout notes, the context must be MainActivity:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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="match_parent"
tools:context="com.SoCu.CirDocu.MainActivity">

</android.support.design.widget.CoordinatorLayout>

You can play putting things inside the AppBarLayout and Toolbar, so that it stays the way you like it.

In the apuntes.xml you can change the ConstraintLayout for a NestedScrollView, in case to put the horizontal mobile something is cut, that is already as you see:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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="match_parent"
    android:fillViewport="false"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.SoCu.CirDocu.MainActivity"
    tools:showIn="@layout/activity_main">

</android.support.v4.widget.NestedScrollView>
    
answered by 09.09.2018 в 23:30