2016-12-01 45 views
1

即使我将定位点设置为bottom|right,我也无法在我的应用程序的右下方插入晶圆厂图标,请大家帮我这么做,因为晶圆厂图标显示在应用程序的左上角。无法将我的晶圆厂图标设置到我的页面右下方

<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/main_content" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:context="com.example.kun.carkila.OwnerTabs"> 

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

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

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.v7.widget.Toolbar 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:minHeight="?attr/actionBarSize" 
     android:background="#990000" 
     app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingTop="@dimen/appbar_padding_top" 
    android:theme="@style/AppTheme.AppBarOverlay" 
    android:background="#990000"> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     /> 

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



<android.support.v4.view.ViewPager 
    android:id="@+id/container" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 


</LinearLayout> 

+0

我相信你的父'ViewGroup'必须是'CoordinatorLayout'才能将'Views'锚定到彼此。 – Emmanuel

+0

@Emmanuel - 是的,该linearLayout的下一个父级是协调员布局。 – JosephG

+0

@Emmanuel - 更新代码先生 – JosephG

回答

1

这应该工作!使用

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

<android.support.design.widget.FloatingActionButton 
       android:layout_alignParent="true" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentBottom="true" 
       android:id="@+id/fab" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="right" 
       android:layout_margin="@dimen/fab_margin" 
       app:srcCompat="@drawable/ic_directions_car_white_48dp" 
       app:layout_anchorGravity="bottom|right" /> 

哇你在哪里的相对布局消失了,这是这个浮动按钮的父母?

2

首先,使用锚属性,你应该有CoordinatorLayout作为父视图。 其次,您的浮动按钮视图位于AppBarLayout中,它始终位于屏幕顶部。

将浮动按钮从AppBarLayout中移出,并将useCoordinatorLayout作为父视图。

+0

但是,当它在协调器布局(这是线性布局的下一个父代。晶圆厂图标不可点击。 – JosephG

+0

更新代码先生 – JosephG