1

Buen dia.

introducir la descripción de la imagen aquí

¿Como podria lograr esto en mi layout xml? me refiero a tener un botón entre la barra principal y el contenido.

De antemano gracias.

1
  • 1
    Hola devjav. Esta pregunta es muy amplia. en tu caso tendrias que mostrarnos el codigo de la aplicacion que estas trabajando y lo que has intentado o te falla. Un saludo
    – lois6b
    el 23 ene. 2017 a las 15:02

1 respuesta 1

3

Esto lo puedes realizar con el CoordinatorLayout en combinación con el AppBarLayout y el CollapsingToolbarLayout, en este caso se fijan los componentes al AppBarLayout, en este caso el FloatingActionButton.

A tu botón le configuras las propiedades:

app:layout_anchor="@id/appbarLayout"
app:layout_anchorGravity="bottom|right|end" 

En la propiedad app:layout_anchor defines el id del AppBarLayout.

Ejemplo:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/btnFab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="16dp"
    android:src="@drawable/ic_fab_icon"
    app:borderWidth="0dp"
    app:layout_anchor="@id/appbarLayout"
    app:layout_anchorGravity="bottom|right|end" />

introducir la descripción de la imagen aquí

Este es un ejemplo completo:

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/background_light"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/main.appbar"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/main.collapsing"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginEnd="64dp">

            <ImageView
                android:id="@+id/main.backdrop"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:fitsSystemWindows="true"
                android:src="@drawable/material_flat"
                app:layout_collapseMode="parallax"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/main.toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin"/>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="20sp"
            android:lineSpacingExtra="8dp"
            android:text="@string/lorem"
            android:padding="@dimen/activity_horizontal_margin"/>
    </android.support.v4.widget.NestedScrollView>

    <!-- Definicion del FloatingActionButton --> 

    <android.support.design.widget.FloatingActionButton
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_margin="@dimen/activity_horizontal_margin"
        android:src="@drawable/ic_comment_24dp"
        app:layout_anchor="@id/main.appbar"
        app:layout_anchorGravity="bottom|right|end"/>

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

Tu Respuesta

Al pulsar en “Publica tu respuesta”, muestras tu consentimiento a nuestros términos de servicio, política de privacidad y política de cookies

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.