0

I have a include block in my XML file Im trying to start a new activity in this include,not full screen, and more important behave like the current layout in that part.

<?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"
    android:fitsSystemWindows="true"
    tools:context="com.example.rt.giftcard.ScrollingActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:background="@color/material_deep_teal_500">

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

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


    <include layout="@layout/content_scrolling"
        android:id="@+id/page_content" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|end" />

I first tried to change the layout of include maybe fragments are solution but I dont know how?

Tavak
  • 3
  • 3

1 Answers1

0

Yes, I think that you're definitely looking to use a fragment instead of an include. You can read more about Fragments here but it's a few steps you have to take.

1) Replace your <include> tag with a <fragment> tag. Define your attributes, which should include a name and id.

2) Define your Fragment class. The name in your <fragment> tag should reference a class that inherits from Fragment. A Fragment is similar to a typical Activity, so the learning curve shouldn't be that bad.

3) In the parent Activity get an instance of the FragmentManager in order to make a FragmentTransaction that adds the fragment to the current screen. It sounds like a lot, I know but someone explains it briefly here.

I hope that helps. Once you get used to making Fragments this should be a breeze.

Community
  • 1
  • 1
arjabbar
  • 6,044
  • 4
  • 30
  • 46