7

यहां एक नया हिस्सा है। मैं एंड्रॉइड विकास में लगभग दो महीने का हूं, लेकिन मेरे पास अन्य वातावरण में वर्षों का विकास अनुभव है।फ़्लोटिंगएक्शन बटन, लेआउट_एंचर और लेआउट_ग्रैविटी

ठीक है। मेरे पास FloatingActionButton है जो यह प्रदर्शित नहीं कर रहा था कि मुझे इसकी उम्मीद थी या यह चाहिए था। यह CoordinatorLayout के अंदर AppBarLayout/Toolbar के साथ और ListView के साथ है।

यहाँ लेआउट है:

<?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/fragment_coordinator" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context=".ViewVehicleList"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fitsSystemWindows="true" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      android:title="Vehicle List" 
      app:layout_scrollFlags="scroll|enterAlways|snap" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> 

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

    <ListView 
     android:id="@+id/Vehicle_ListView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     android:background="#FFFFFF" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    </ListView> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab_AddVehicle" 
     style="@style/FloatingAddButton" 
     android:src="@drawable/ic_green_add" 
     android:layout_gravity="bottom|end" 
     app:layout_anchor="@id/Vehicle_ListView" 
     android:onClick="addVehicle"/> 

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

इस लेआउट के साथ, स्क्रीन इस तरह दिखता है: FAB in wrong position

मेरे layout_gravity कहते हैं "bottom|end"। मैंने इसे "bottom|right" में बदल दिया, लेकिन एक ही परिणाम मिला। मैंने कई ट्यूटोरियल्स के माध्यम से पढ़ा है, और स्टैक ओवरफ्लो का शोध किया है, और कोई भाग्य नहीं है। एक फैब का उपयोग करें और यह ठीक से स्थिति आप layout_anchor और layout_gravity उपयोग करने की आवश्यकता करने के लिए:

मैं फैब तत्व app:layout_anchor="@id/Vehicle_ListView", जो मैं क्या पढ़ा के लिए काउंटर चलाने के लिए लगता है में सूचीबद्ध लंगर निकाल कर इसे हल करने में कामयाब रहे। एंकर टैग के बिना, यह इस तरह दिखता है:

FAB in correct position

तो यहाँ मेरे सवाल है: क्यों मेरी लंगर मेरे FloatingActionButton की स्थिति पंगा लेना है? मैं क्या गलत कर रहा हूं?

उत्तर

11

-boster तुम बस layout_anchorGravity जोड़ने की जरूरत है।

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab_AddVehicle" 
    style="@style/FloatingAddButton" 
    android:src="@drawable/ic_green_add" 
    android:onClick="addVehicle" 
    app:layout_anchor="@id/Vehicle_ListView" 
    app:layout_anchorGravity="bottom|end" /> 
संबंधित मुद्दे