布局之间的FAB [英] FAB between layouts
问题描述
这是我的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:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/layout_first"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.8"
android:background="@color/ColorPrimary"
android:orientation="horizontal" />
<LinearLayout
android:id="@+id/layout_second"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:background="@color/ColorPrimaryLight"
android:orientation="horizontal" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:clickable="true"
android:src="@drawable/ic_search_black_48dp"
app:backgroundTint="#df0909"
app:elevation="4dp"
app:layout_anchor="@id/layout_first"
app:layout_anchorGravity="bottom|right|end" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
这就是它的外观:
I tried it from this answer: How can I add the new "Floating Action Button" between two widgets/layouts
但是当我将compile 'com.android.support:design:23.4.0'
更改为compile 'com.android.support:design:25.0.1'
时,出现错误:
But when I changed compile 'com.android.support:design:23.4.0'
to compile 'com.android.support:design:25.0.1'
I'm getting an error:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.test.test"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
}
因此,有一种方法可以实现这样的外观,其中晶圆厂位于两种布局之间(无需滚动):
So is there a way to achieve a look like this, where the fab is between two layouts (no scrolling needed):
推荐答案
您的FloatingActionButton
在LinearLayout
内部.为了使layout_anchor*
属性起作用,它必须是CoordinatorLayout
的直接子代.
Your FloatingActionButton
is inside a LinearLayout
. For the layout_anchor*
attributes to work, it needs to be a direct child of the CoordinatorLayout
.
只需将FloatingActionButton
元素移到结束LinearLayout
标记之后.
Simply move the FloatingActionButton
element to after the closing LinearLayout
tag.
这篇关于布局之间的FAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!