22

में काम नहीं कर मैं एक CoordinatorLayout में एक Recyclerview के साथ FloatingActionButton प्रदर्शित कर रहा हूँ, जब फैब क्लिक किया जाता है एक पंक्ति Recyclerview में जोड़ा जाएगा। अब समस्या यह है कि जब मैंने एपीआई 15 में परीक्षण किया था तो एफएबी का मार्जिन था, लेकिन जब मैं एपीआई 22 (लॉलीपॉप 5.1.1-नेक्सस 4) में परीक्षण करता हूं तो मुझे कोई मार्जिन नहीं मिलता है और स्क्रीन के किनारे पर एफएबी दबाया जाता है।FloatingActionButton डिफ़ॉल्ट मार्जिन लॉलीपॉप

मेरी चिंता है कि एफएबी में एपीआई 15 में डिफ़ॉल्ट मार्जिन सेटअप है (अन्य उपकरणों का परीक्षण नहीं किया गया है) लेकिन एपीआई 22 में नहीं है या मुझे कुछ याद आ रही है।

मेरे लेआउट कोड:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#6fbababa" 
    android:fitsSystemWindows="true"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/my_recycler_view" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:clipToPadding="false" 
     android:paddingBottom="@dimen/fab_padding_bottom" 
     android:scrollbars="vertical" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#ffffff"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:fitsSystemWindows="true" 
      android:orientation="horizontal" 
      app:layout_scrollFlags="scroll|enterAlwaysCollapsed"> 
      --------------------- 
      ---------------------  
     </LinearLayout> 

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

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/button_floating_action" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:clickable="true" 
     android:src="@drawable/ic_plus" 
     app:borderWidth="0dp" 
     app:layout_anchor="@id/my_recycler_view" 
     app:layout_anchorGravity="bottom|right|end" 
     app:rippleColor="@color/wallet_highlighted_text_holo_light" /> 

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

enter image description here

+1

http://stackoverflow.com/questions/30687888/android-design-library-floating-action-button-padding-margin-issues – goonerDroid

+0

के लिंक पर आधारित मैं पुस्तकालय के साथ एक मुद्दा देखता हूं। – Psypher

उत्तर

14

मैं एपीआई विशेष मार्जिन मानों का उपयोग कर समाप्त हो गया। मेरे एक्शन बटन इस तरह है:

<dimen name="action_button_margin">0dp</dimen> 

और मूल्यों-V21 में/dimens.xml:

<dimen name="action_button_margin">16dp</dimen> 
0

मैं

<android.support.design.widget.FloatingActionButton 
    android:contentDescription="@string/menu_compose" 
    android:id="@+id/action" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:clickable="true" 
    android:src="@drawable/ic_create_white" 
    android:layout_gravity="bottom|right|end" 
    android:layout_marginBottom="@dimen/action_button_margin" 
    android:layout_marginRight="@dimen/action_button_margin" 
    android:layout_marginEnd="@dimen/action_button_margin" 
    app:elevation="6dp" 
    app:pressedTranslationZ="12dp" 
    app:fabSize="normal"/> 

@dimen/action_button_margin दोनों मूल्यों/dimens.xml में परिभाषित किया गया है मान लें कि this question में वर्णित एक ही समस्या है। विभिन्न मार्जिन की गणना की जा रही छाया की वजह से या एपीआई संस्करण के आधार पर नहीं है।

16

बस का उपयोग करें:

app:useCompatPadding="true" 

इस आवश्यक अंतरिक्ष जोड़ना चाहिए।

+4

हाँ, स्वीकृत उत्तर –

+0

होना चाहिए यह मेरे लिए ठीक काम करता है। thenks –

संबंधित मुद्दे