2016-11-23 10 views
0

안녕하세요 Android 개발자의 새로운 기능입니다. 나는 목록보기를 스크롤 할 때Android가 고정 위치의 부동 동작 메뉴를 만듭니다.

listView.setNestedScrollingEnabled(true); 

상단 도구 모음을 숨길 수 :

나는 아래의 코드를 설정합니다. 그러나 플로팅 동작 메뉴를 포함하여 모든 하위 뷰가 이동됩니다.

플로팅 작업 메뉴를 유휴 상태로 유지하고 위치를 고정하고 NestedScrollingEnabled 동작의 영향을받지 않길 원합니다. 분명히 부모보기에 영향을 미칩니다.

enter image description here

이에 대한 모든 솔루션을? 고맙습니다.

내 XML은 약이 (너무 길어서 그냥하는 XML 코드에서 ABIT 다른 첨부 된 이미지를 무시하지만 일반적인 생각이있다)과 같은

:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:fab="http://schemas.android.com/apk/res-auto" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:id="@+id/fragment_price_layout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="#e3e3e3"> 

    <android.support.v4.widget.SwipeRefreshLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/swipeContainer" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@+id/buttons_selection_container"> 

      <FrameLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <ProgressBar 
       android:id="@+id/progressBar" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginBottom="15dp" 
       android:indeterminateTint="@color/colorProgressBarPrimary" 
       android:indeterminateTintMode="src_atop"/> 

       <TextView 
       android:id="@+id/textView_no_data" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="No Price Data" 
       android:layout_gravity="center_horizontal|center_vertical" 
       android:textStyle="bold" 
       android:textSize="18dp" 
       android:visibility="gone"/> 

       <ListView 
       android:id="@+id/listView_prices" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:nestedScrollingEnabled="true"> 
       </ListView> 
      </FrameLayout> 
    </android.support.v4.widget.SwipeRefreshLayout> 

    <com.getbase.floatingactionbutton.FloatingActionsMenu 
     android:id="@+id/price_fragment_float_Menu_button" 
     android:layout_width="322dp" 
     android:layout_height="376dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_marginBottom="46dp" 
     android:layout_marginRight="10dp" 
     fab:fab_addButtonColorNormal="@color/color_float_blue_dark" 
     fab:fab_addButtonColorPressed="@color/colorAccent" 
     fab:fab_addButtonPlusIconColor="@color/white"> 

     <com.getbase.floatingactionbutton.FloatingActionButton 
      android:id="@+id/button_switch_price" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      fab:fab_colorNormal="@color/color_float_blue_lite" 
      fab:fab_colorPressed="@color/colorAccent" 
      fab:fab_icon="@drawable/button_different_currencies" 
      fab:fab_size="mini" 
      fab:fab_title="Switch Price"/> 
    </com.getbase.floatingactionbutton.FloatingActionsMenu> 
</RelativeLayout> 
+0

다른보기에서 부동 버튼 만들기 및 레이아웃 포함 – Vadivel

+0

맞춤 설정 대신 [Google FAB 버튼] (https://guides.codepath.com/android/floating-action-buttons)을 사용하십시오. –

답변

0

당신은 숨길 수 있습니다 목록보기가

public class ScrollingFABBehavior extends FloatingActionButton.Behavior { 


private static final String TAG = "ScrollingFABBehavior"; 

public ScrollingFABBehavior(Context context, AttributeSet attrs) { 
    super(); 
    // Log.e(TAG, "ScrollAwareFABBehavior"); 
} 


public boolean onStartNestedScroll(CoordinatorLayout parent, FloatingActionButton child, View directTargetChild, View target, int nestedScrollAxes) { 

    return true; 
} 

@Override 
public boolean layoutDependsOn(CoordinatorLayout parent, FloatingActionButton child, View dependency) { 
    if (dependency instanceof RecyclerView) 
     return true; 

    return false; 
} 

@Override 
public void onNestedScroll(CoordinatorLayout coordinatorLayout, 
          FloatingActionButton child, View target, int dxConsumed, 
          int dyConsumed, int dxUnconsumed, int dyUnconsumed) { 
    // TODO Auto-generated method stub 
    super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, 
      dxUnconsumed, dyUnconsumed); 
    //Log.e(TAG, "onNestedScroll called"); 
    if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) { 
    // Log.e(TAG, "child.hide()"); 
     child.hide(); 
    } else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) { 
     // Log.e(TAG, "child.show()"); 
     child.show(); 
    } 
}} 

레이아웃 XML atrribute 사용자 지정 레이아웃 동작을 사용하여 스크롤 FAB 버튼

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/imageViewYes" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end|right" 
    android:layout_margin="@dimen/fab_margin" 
    android:src="@drawable/ic_yes" 
    app:backgroundTint="@color/white" 
    android:scaleType="center" 
    app:elevation="6dp" 
    app:fabSize="normal" 
    app:layout_behavior="com.your.package.ScrollingFABBehavior" /> 
+0

좋지 않습니다. 사용자가 항상 플로팅 버튼을보고 싶습니다. 목록보기가 결과의 마지막 행에 도달하면 0.4f로만 사라집니다. 내 솔루션은 이제까지 아무도 없습니다. 스크롤 동작에 따라 위/아래로 두십시오. 플로팅 버튼을 listview 레이아웃 안에 넣으려고합니다. – felixwcf