Fab 표시 위아래 2개

8510 단어 Android
이렇게 간단한 일을 못 하고 푹 빠져 있다니.먼저 움직였으니까 필기해.

프로젝트를 만들려면 Basic Activity 를 선택합니다.



activity_main.xml 열기


비디오(id=space)의 android:layoutheight="150dp"
이 150dp 부분은 FAB 사이의 공간이 된다.
activity_main.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"
    android:fitsSystemWindows="true"
    tools:context="jp.co.test.doublefab.MainActivity">

    <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" />

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

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

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

    <View
        android:id="@+id/space"
        android:layout_width="1dp"
        android:layout_height="150dp"
        app:layout_anchor="@id/bottom"
        app:layout_anchorGravity="top|right|end" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/top"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        app:layout_anchor="@id/space"
        app:layout_anchorGravity="top|right|end"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@android:drawable/ic_dialog_email" />

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

MainActivity.java

   FloatingActionButton topFab = (FloatingActionButton) findViewById(R.id.top);
        FloatingActionButton bottomFab = (FloatingActionButton) findViewById(R.id.bottom);

        topFab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "上のFABがクリックされた", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        bottomFab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "下のFABがクリックされた", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

좋은 웹페이지 즐겨찾기