2015-11-05 60 views

回答

1

此功能,只有当你的父母布局是一个协调layout.This可以使用app:layout_anchor=""app:layout_anchorGravity=""

有些事情是这样实现的工作原理:

<?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/com.example.myapp" 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="#ffffff" 
    > 
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content" 
              android:layout_width="match_parent" 
              android:id="@+id/appBar" 
     > 
    <!-- Put your content that is supposed to be in the appbar here --> 

</android.support.design.widget.AppBarLayout> 
<android.support.design.widget.FloatingActionButton 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:src="@drawable/your_drawable_resource_file" 
     app:borderWidth="0dp" 
     app:fabSize="normal" 
     app:layout_anchor="@id/appBar" 
     app:layout_anchorGravity="left|bottom|start"/> 
</android.support.design.widget.CoordinatorLayout> 

希望这很有帮助。

1

如果你的父母布局相对布局。 只需使用

android:layout_alignParentRight="true" 
    android:layout_alignParentBottom="true" 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:clickable="true" 
android:orientation="vertical"> 



    <android.support.design.widget.FloatingActionButton 
    android:layout_alignParentRight="true" 
    android:layout_alignParentBottom="true" 
    android:id="@+id/myFAB" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_plus_sign" 
    app:elevation="4dp" 
/> 

</RelativeLayout> 
+1

不为我工作:/ – Muffin

+0

你可以提供你的xml文件作为更多的参考 –

+1

我没有直接针对该问题的xml ^^ 我只是需要它,因为它是我附加在我的问题 – Muffin