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();
}
});
Reference
이 문제에 관하여(Fab 표시 위아래 2개), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/araiyusuke/items/ff2880e3c7fe22a1400a텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)