2016-07-11 40 views
0

我製作了片段A覆蓋另一個片段B的全屏。我想處理可以關閉片段的滑動觸摸向上滑動並重新打開它向下滑動。可以關閉的另一個片段的片段向上滑動

我做了這個例子形象: enter image description here

我如何能實現呢?我還沒有找到這個特例的任何教程。謝謝。

+0

如果你修改[驗證碼](http://stackoverflow.com/questions/4139288/android-how-to-handle-right-to - 左手輕掃手勢)上下可以使用FragmentManager來處理所需的片段。 –

+0

ty回覆,現在我試試 –

回答

0

compile 'me.imid.swipebacklayout.lib:library:1.0.0'

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.darwich.swipetoclose.MainActivity"> 

    <RadioGroup 
     android:id="@+id/id_radioGroup" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="40dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

     <RadioButton 
      android:id="@+id/mode_left" 
      android:text="Left" 
      android:textSize="24sp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <RadioButton 
      android:id="@+id/mode_right" 
      android:text="Right" 
      android:textSize="24sp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <RadioButton 
      android:id="@+id/mode_bottom" 
      android:text="Bottom" 
      android:textSize="24sp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <RadioButton 
      android:id="@+id/all" 
      android:text="All" 
      android:textSize="24sp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

    </RadioGroup> 

</RelativeLayout> 
public class MainActivity extends SwipeBackActivity { 

    private SwipeBackLayout swipeBackLayout; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     RadioGroup trackingModeGroup = (RadioGroup) findViewById(R.id.id_radioGroup); 
     swipeBackLayout = getSwipeBackLayout(); 

     trackingModeGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(RadioGroup group, int checkedId) { 
       int edgeFlag; 
       switch (checkedId) { 
        case R.id.mode_left: 
         edgeFlag = SwipeBackLayout.EDGE_LEFT; 
         break; 
        case R.id.mode_right: 
         edgeFlag = SwipeBackLayout.EDGE_RIGHT; 
         break; 
        case R.id.mode_bottom: 
         edgeFlag = SwipeBackLayout.EDGE_BOTTOM; 
         break; 
        default: 
         edgeFlag = SwipeBackLayout.EDGE_ALL; 
       } 
       swipeBackLayout.setEdgeTrackingEnabled(edgeFlag); 
      } 
     }); 
    } 
} 
相關問題