Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ Very little code, are all here
代码非常少,都在这里

[ParallaxSwipeBackActivity](https://github.com/bushijie/ParallaxSwipeBack/blob/master/app/src/main/java/com/bureak/parallaxswipeback/ParallaxSwipeBackActivity.java)

解决侧滑与ViewPager滑动冲突
-----


Thinks
-----

[http://blog.csdn.net/hanhailong726188/article/details/46433229](http://blog.csdn.net/hanhailong726188/article/details/46433229)
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<activity
android:name=".NextActivity"
android:theme="@style/AppTranslucentTheme" />
<activity
android:name=".ViewPagerActivity"
android:theme="@style/AppTranslucentTheme" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.bureak.parallaxswipeback;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class FragmentPage1Fragment
extends Fragment
{
TextView textView;

// 要显示的视图
protected View currentView = null;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
currentView = inflater.inflate(R.layout.fragment_page, container, false);
return currentView;
}

@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);

textView = (TextView) currentView.findViewById(R.id.tv_fragment_page);

// 初始化
init();
}

/**
* 初始化
*/
protected void init()
{
textView.setText("页卡1");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.bureak.parallaxswipeback;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class FragmentPage2Fragment
extends Fragment
{
TextView textView;

// 要显示的视图
protected View currentView = null;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
currentView = inflater.inflate(R.layout.fragment_page, container, false);
return currentView;
}

@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);

textView = (TextView) currentView.findViewById(R.id.tv_fragment_page);

// 初始化
init();
}

/**
* 初始化
*/
protected void init()
{
textView.setText("页卡2");
}
}
34 changes: 24 additions & 10 deletions app/src/main/java/com/bureak/parallaxswipeback/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,55 @@
* @Description: 主界面
* Created by [email protected] on 2015/7/5.
*/
public class MainActivity extends ParallaxSwipeBackActivity {
public class MainActivity
extends ParallaxSwipeBackActivity
{

@Override
protected void onCreate(Bundle savedInstanceState) {
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.next).setOnClickListener(new View.OnClickListener() {
findViewById(R.id.next).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,NextActivity.class);
intent.putExtra("index",0);
public void onClick(View v)
{
Intent intent = new Intent(MainActivity.this, NextActivity.class);
intent.putExtra("index", 0);
startParallaxSwipeBackActivty(MainActivity.this, intent);
}
});

}

public void onClick(View view)
{
Intent intent = new Intent(this, ViewPagerActivity.class);
startActivity(intent);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
public boolean onOptionsItemSelected(MenuItem item)
{
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
if (id == R.id.action_settings)
{
Uri uri = Uri.parse("https://github.com/bushijie/ParallaxSwipeBack");
startActivity(new Intent(Intent.ACTION_VIEW,uri));
startActivity(new Intent(Intent.ACTION_VIEW, uri));
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.bureak.parallaxswipeback;

/**
* Created by 杨永青 on 2015/8/21.
*/

import android.content.Context;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.widget.SlidingPaneLayout;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewConfiguration;

/**
* Created by apaojun on 2015/2/12.
*/
public class PagerEnabledSlidingPaneLayout
extends SlidingPaneLayout
{

private float mInitialMotionX;
private float mInitialMotionY;
private float mEdgeSlop;

public PagerEnabledSlidingPaneLayout(Context context)
{
this(context, null);
}

public PagerEnabledSlidingPaneLayout(Context context, AttributeSet attrs)
{
this(context, attrs, 0);
}

public PagerEnabledSlidingPaneLayout(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);

ViewConfiguration config = ViewConfiguration.get(context);
mEdgeSlop = config.getScaledEdgeSlop();
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{

switch (MotionEventCompat.getActionMasked(ev))
{
case MotionEvent.ACTION_DOWN:
{
mInitialMotionX = ev.getX();
mInitialMotionY = ev.getY();
break;
}

case MotionEvent.ACTION_MOVE:
{
final float x = ev.getX();
final float y = ev.getY();
// The user should always be able to "close" the pane, so we only check
// for child scrollability if the pane is currently closed.
if (mInitialMotionX > mEdgeSlop && !isOpen() && canScroll(this, false,
Math.round(x - mInitialMotionX), Math.round(x), Math.round(y)))
{

// How do we set super.mIsUnableToDrag = true?

// send the parent a cancel event
MotionEvent cancelEvent = MotionEvent.obtain(ev);
cancelEvent.setAction(MotionEvent.ACTION_CANCEL);
return super.onInterceptTouchEvent(cancelEvent);
}
}
}

return super.onInterceptTouchEvent(ev);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import android.support.v4.widget.SlidingPaneLayout;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
Expand All @@ -30,7 +29,7 @@ public class ParallaxSwipeBackActivity extends AppCompatActivity implements Slid
private final static String TAG = ParallaxSwipeBackActivity.class.getSimpleName();
private final static String WINDOWBITMAP = "screenshots.jpg";
private File mFileTemp;
private SlidingPaneLayout slidingPaneLayout;
private PagerEnabledSlidingPaneLayout slidingPaneLayout;
private FrameLayout frameLayout;
private ImageView behindImageView;
private ImageView shadowImageView;
Expand All @@ -41,7 +40,7 @@ public class ParallaxSwipeBackActivity extends AppCompatActivity implements Slid
protected void onCreate(Bundle savedInstanceState) {
//通过反射来改变SlidingPanelayout的值
try {
slidingPaneLayout = new SlidingPaneLayout(this);
slidingPaneLayout = new PagerEnabledSlidingPaneLayout(this);
Field f_overHang = SlidingPaneLayout.class.getDeclaredField("mOverhangSize");
f_overHang.setAccessible(true);
f_overHang.set(slidingPaneLayout, 0);
Expand Down
Loading