-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d13d416
commit ea4c6a7
Showing
41 changed files
with
1,458 additions
and
299 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package cq.airbnb; | ||
|
||
import android.os.Bundle; | ||
import android.support.design.widget.CoordinatorLayout; | ||
import android.support.design.widget.TabLayout; | ||
import android.support.v4.view.ViewPager; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
import android.widget.LinearLayout; | ||
|
||
import cq.behaviordemo.R; | ||
import cq.behaviordemo.adapter.ItemAdapter; | ||
|
||
/** | ||
* 仿爱彼迎主页 | ||
*/ | ||
|
||
public class AirbnbActivity extends AppCompatActivity { | ||
private TabLayout mTabLayout; | ||
private ViewPager mViewPager; | ||
private LinearLayout mLytUP; | ||
private LinearLayout mLytAll; | ||
|
||
@Override protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_airbnb); | ||
findView(); | ||
initView(); | ||
initEvent(); | ||
mTabLayout.setTranslationY(getResources().getDimensionPixelOffset(R.dimen.airbnb_translation_min)); | ||
} | ||
|
||
private void findView() { | ||
mTabLayout = (TabLayout) findViewById(R.id.tab_layout); | ||
mViewPager = (ViewPager) findViewById(R.id.viewpager); | ||
mLytUP = (LinearLayout) findViewById(R.id.lyt_up); | ||
mLytAll = (LinearLayout) findViewById(R.id.lyt_all); | ||
|
||
mLytUP.setOnClickListener(new View.OnClickListener() { | ||
@Override public void onClick(View v) { | ||
((TabBehavior) ((CoordinatorLayout.LayoutParams) mTabLayout.getLayoutParams()).getBehavior()).hideItem(); | ||
|
||
} | ||
}); | ||
mLytAll.setOnClickListener(new View.OnClickListener() { | ||
@Override public void onClick(View v) { | ||
((TabBehavior) ((CoordinatorLayout.LayoutParams) mTabLayout.getLayoutParams()).getBehavior()).needExpand(); | ||
|
||
} | ||
}); | ||
} | ||
|
||
private void initView() { | ||
mViewPager.setAdapter(new ItemAdapter(getSupportFragmentManager(), mViewPager, 2)); | ||
mTabLayout.setupWithViewPager(mViewPager); | ||
} | ||
|
||
private void initEvent() { | ||
mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { | ||
@Override | ||
public void onTabSelected(TabLayout.Tab tab) { | ||
mViewPager.setCurrentItem(tab.getPosition()); | ||
} | ||
|
||
@Override | ||
public void onTabUnselected(TabLayout.Tab tab) { | ||
|
||
} | ||
|
||
@Override | ||
public void onTabReselected(TabLayout.Tab tab) { | ||
|
||
} | ||
}); | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package cq.airbnb; | ||
|
||
import android.content.Context; | ||
import android.support.design.widget.CoordinatorLayout; | ||
import android.support.design.widget.TabLayout; | ||
import android.util.AttributeSet; | ||
import android.view.View; | ||
|
||
import cq.behaviordemo.R; | ||
|
||
/** | ||
* 背景的behavior | ||
*/ | ||
|
||
public class BGBehavior extends CoordinatorLayout.Behavior { | ||
|
||
private int mTranslationMax; | ||
public BGBehavior(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
mTranslationMax=context.getResources().getDimensionPixelOffset(R.dimen.airbnb_translation_max); | ||
} | ||
|
||
|
||
@Override public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) { | ||
return dependency instanceof TabLayout; | ||
} | ||
|
||
@Override public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) { | ||
child.setTranslationY(dependency.getTranslationY()-mTranslationMax); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package cq.airbnb; | ||
|
||
import android.content.Context; | ||
import android.support.design.widget.CoordinatorLayout; | ||
import android.support.design.widget.TabLayout; | ||
import android.util.AttributeSet; | ||
import android.view.View; | ||
|
||
import java.util.List; | ||
|
||
import cq.behaviordemo.R; | ||
import cq.behaviordemo.behavior.HeaderScrollingViewBehavior; | ||
|
||
/** | ||
* 控制列表的移动 | ||
*/ | ||
|
||
public class ListBehavior extends HeaderScrollingViewBehavior { | ||
private int mHeightToolbar; | ||
public ListBehavior(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
mHeightToolbar=context.getResources().getDimensionPixelOffset(R.dimen.toolbar_height); | ||
} | ||
|
||
|
||
@Override | ||
public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) { | ||
return isDependOn(dependency); | ||
} | ||
|
||
|
||
@Override public View findFirstDependency(List<View> views) { | ||
for (View view : views) { | ||
if (isDependOn(view)) | ||
return view; | ||
} | ||
return null; | ||
} | ||
|
||
@Override protected int getScrollRange(View v) { | ||
if (isDependOn(v)) { | ||
return 0; | ||
} else { | ||
return super.getScrollRange(v); | ||
} | ||
} | ||
|
||
private boolean isDependOn(View dependency) { | ||
return dependency instanceof TabLayout; | ||
} | ||
|
||
//跟随tab移动 | ||
@Override | ||
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) { | ||
|
||
child.setTranslationY(dependency.getTranslationY()); | ||
return true; | ||
} | ||
} |
Oops, something went wrong.