2017-04-24 2 views
0

Ich möchte ausblenden oder zeigen Sie die aktuelle_layout beim Streichen über eine Schaltfläche. Wie implementiere ich es über eine Schaltfläche in Android wischen?Allmählich zeigen oder verstecken ein Layout beim Wischen auf eine Schaltfläche in Android

<RelativeLayout 
    android:id="@+id/recent_layout" 
    android:layout_width="match_parent" 
    android:layout_below="@+id/img_layout" 
    android:background="@color/player_light_alpha" 
    android:visibility="invisible" 
    app:layout_behaviour="@string/appbar_scrolling_view_behavior" 
    app:layout_heightPercent="@fraction/recent_fraction"> 

    <RelativeLayout 
     android:id="@+id/list_switcher_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 


     <com.ibytecode.radioapp.view.LatoRegularTextView 
      android:id="@+id/recently_played_txt" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_gravity="center" 
      android:layout_margin="@dimen/common_margin_8" 
      android:background="@drawable/selector_bg" 
      android:drawableLeft="@drawable/ic_recent" 
      android:gravity="center" 
      android:onClick="@{(view) -> presenter.onClick(view)}" 
      android:tag="@{tag.RECENTS}" 
      android:text="@string/recently_played" 
      android:textColor="@android:color/white" 
      android:textSize="@dimen/channel_name_size" /> 


     <com.ibytecode.radioapp.view.LatoRegularTextView 
      android:id="@+id/favs_txt" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_gravity="center" 
      android:layout_margin="@dimen/common_margin_8" 
      android:background="@drawable/selector_bg" 
      android:drawableLeft="@drawable/ic_favourite" 
      android:gravity="center" 
      android:onClick="@{(view) -> presenter.onClick(view)}" 
      android:tag="@{tag.FAVOURITES}" 
      android:text="@string/favourites" 
      android:textColor="@android:color/white" 
      android:textSize="@dimen/channel_name_size" /> 


     <com.ibytecode.radioapp.view.LatoRegularTextView 
      android:id="@+id/related_txt" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_gravity="center" 
      android:layout_margin="@dimen/common_margin_8" 
      android:background="@drawable/selector_bg" 
      android:drawableLeft="@drawable/ic_favourite" 
      android:gravity="center" 
      android:onClick="@{(view) -> presenter.onClick(view)}" 
      android:tag="@{tag.RELATED}" 
      android:text="@string/related_items" 
      android:textColor="@android:color/white" 
      android:textSize="@dimen/channel_name_size" /> 


    </RelativeLayout> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recent_recycler_view" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/list_switcher_layout" 
     android:layout_below="@+id/list_switcher_layout" 
     android:layout_marginTop="@dimen/recent_recyler_margin" /> 

    <ImageView 
     android:id="@+id/no_content_img" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:visibility="gone" /> 

</RelativeLayout> 

Antwort

0
private float x1,x2; 
static final int DISTANCE = 100; 

und setOnTouchListener auf den Knopf. und dann außer Kraft setzen onTouchEvent:

@Override 
public boolean onTouchEvent(MotionEvent event) 
{  
switch(event.getAction()) 
{ 
    case MotionEvent.ACTION_DOWN: 
     x1 = event.getX();       
    break;   
    case MotionEvent.ACTION_UP: 
     x2 = event.getX(); 
     float deltaX = x2 - x1; 
     if (Math.abs(deltaX) > MIN_DISTANCE){ 
      findViewById(R.id.recent_layout).setVisibility(View.GONE); 
     }       
    break; 
}   
return super.onTouchEvent(event);  
} 
+0

Dank bro für Ihre wertvolle Antwort wurde scrotching meinen Kopf –

+0

Accept als richtige Antwort, ob es geholfen. –

Verwandte Themen