Created
March 2, 2015 17:01
-
-
Save ipopza/610948feea3448a66e8a to your computer and use it in GitHub Desktop.
Show read more content like Google player store : demo https://www.youtube.com/watch?v=JpqOkdBfjdg
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
public class GGPlayReadMoreActivity extends ActionBarActivity implements View.OnClickListener { | |
private ActionBar actionBar; | |
private ScrollView firstPage; | |
private TextView tvTop; | |
private TextView tvMid; | |
private TextView tvBottom; | |
private View vContent; | |
private float SCREEN_HEIGHT; | |
private boolean mIsOpenedMorePanel; | |
private void setHomeAsUp(boolean isHomeAsUp) { | |
if (actionBar != null) { | |
actionBar.setDisplayHomeAsUpEnabled(isHomeAsUp); | |
} | |
} | |
private void setActionbarColor(int colorResId) { | |
if (actionBar != null) { | |
actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(colorResId))); | |
} | |
} | |
private void setHomeAsUpIcon(int resId) { | |
if (actionBar != null) { | |
actionBar.setHomeAsUpIndicator(resId); | |
} | |
} | |
private void setOpenedMorePanel(boolean isOpenedMorePanel) { | |
mIsOpenedMorePanel = isOpenedMorePanel; | |
if (isOpenedMorePanel) { | |
setActionbarColor(R.color.blue); | |
} else { | |
setActionbarColor(R.color.green); | |
} | |
} | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.layout_ggplay); | |
actionBar = getSupportActionBar(); | |
setActionbarColor(R.color.green); | |
setHomeAsUp(true); | |
Display display = getWindowManager().getDefaultDisplay(); | |
Point size = new Point(); | |
display.getSize(size); | |
SCREEN_HEIGHT = size.y; | |
vContent = (View) findViewById(R.id.view_content); | |
vContent.setVisibility(View.GONE); | |
firstPage = (ScrollView) findViewById(R.id.first_page); | |
tvTop = (TextView) findViewById(R.id.tv_top); | |
tvMid = (TextView) findViewById(R.id.tv_mid); | |
tvBottom = (TextView) findViewById(R.id.tvt_bottom); | |
tvMid.setOnClickListener(this); | |
} | |
@Override | |
public void onClick(View v) { | |
doOpenMorePanel(); | |
} | |
@Override | |
public boolean onSupportNavigateUp() { | |
onBackPressed(); | |
return super.onSupportNavigateUp(); | |
} | |
@Override | |
public void onBackPressed() { | |
if (mIsOpenedMorePanel) { | |
doCloseMorePanel(); | |
} else { | |
super.onBackPressed(); | |
} | |
} | |
private void doOpenMorePanel() { | |
setHomeAsUpIcon(R.drawable.abc_ic_clear_mtrl_alpha); | |
setOpenedMorePanel(true); | |
ObjectAnimator fadeOut = ObjectAnimator.ofFloat(tvMid, View.ALPHA, 1.0f, 0.0f); | |
fadeOut.setDuration(100); | |
fadeOut.start(); | |
new Handler().postDelayed(new Runnable() { | |
@Override | |
public void run() { | |
ObjectAnimator goTop = ObjectAnimator.ofFloat(tvTop, View.TRANSLATION_Y, 0, -1 * tvTop.getHeight()); | |
goTop.setDuration(400); | |
goTop.start(); | |
ObjectAnimator goBottom = ObjectAnimator.ofFloat(tvBottom, View.TRANSLATION_Y, 0, SCREEN_HEIGHT); | |
goBottom.setDuration(400); | |
goBottom.start(); | |
} | |
}, 200); | |
vContent.setVisibility(View.VISIBLE); | |
ObjectAnimator slideIn = ObjectAnimator.ofFloat(vContent, View.TRANSLATION_Y, SCREEN_HEIGHT, 0); | |
slideIn.setDuration(400); | |
slideIn.start(); | |
ObjectAnimator fadeIn = ObjectAnimator.ofFloat(vContent, View.ALPHA, 0.0f, 1.0f); | |
fadeIn.setDuration(800); | |
fadeIn.start(); | |
fadeIn.addListener(new Animator.AnimatorListener() { | |
@Override | |
public void onAnimationStart(Animator animation) { | |
} | |
@Override | |
public void onAnimationEnd(Animator animation) { | |
if (mIsOpenedMorePanel) { | |
firstPage.setVisibility(View.GONE); | |
} | |
} | |
@Override | |
public void onAnimationCancel(Animator animation) { | |
} | |
@Override | |
public void onAnimationRepeat(Animator animation) { | |
} | |
}); | |
} | |
private void doCloseMorePanel() { | |
setHomeAsUpIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha); | |
setOpenedMorePanel(false); | |
vContent.setVisibility(View.GONE); | |
firstPage.setVisibility(View.VISIBLE); | |
ObjectAnimator fadeIn = ObjectAnimator.ofFloat(tvMid, View.ALPHA, 0.0f, 1.0f); | |
fadeIn.setDuration(100); | |
fadeIn.start(); | |
ObjectAnimator goTop = ObjectAnimator.ofFloat(tvTop, View.TRANSLATION_Y, -1 * tvTop.getHeight(), 0); | |
goTop.setDuration(400); | |
goTop.start(); | |
ObjectAnimator goBottom = ObjectAnimator.ofFloat(tvBottom, View.TRANSLATION_Y, SCREEN_HEIGHT, 0); | |
goBottom.setDuration(400); | |
goBottom.start(); | |
} | |
} |
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
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:id="@+id/root" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<include layout="@layout/layout_more" /> | |
<ScrollView | |
android:id="@+id/first_page" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical"> | |
<TextView | |
android:id="@+id/tv_top" | |
android:text="@string/hello_world" | |
android:background="@color/red" | |
android:gravity="center" | |
android:layout_width="match_parent" | |
android:layout_height="@dimen/content_height" /> | |
<TextView | |
android:id="@+id/tv_mid" | |
android:text="@string/readmore" | |
android:gravity="center" | |
android:layout_width="match_parent" | |
android:layout_height="@dimen/content_height_small" /> | |
<TextView | |
android:id="@+id/tvt_bottom" | |
android:text="@string/hello_world" | |
android:background="@color/blue" | |
android:gravity="center" | |
android:layout_width="match_parent" | |
android:layout_height="@dimen/content_height" /> | |
</LinearLayout> | |
</ScrollView> | |
</RelativeLayout> |
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
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:id="@+id/view_content" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:padding="@dimen/activity_horizontal_margin" | |
android:orientation="vertical"> | |
<TextView | |
android:text="@string/readmore" | |
android:gravity="center" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" /> | |
<View | |
android:layout_width="match_parent" | |
android:layout_height="1dp" | |
android:layout_margin="10dp" | |
android:background="@color/blue" /> | |
<TextView | |
android:text="@string/text" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" /> | |
<View | |
android:layout_width="match_parent" | |
android:layout_height="1dp" | |
android:layout_margin="10dp" | |
android:background="@color/blue" /> | |
<TextView | |
android:text="@string/text" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" /> | |
<View | |
android:layout_width="match_parent" | |
android:layout_height="1dp" | |
android:layout_margin="10dp" | |
android:background="@color/blue" /> | |
<TextView | |
android:text="@string/text" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" /> | |
</LinearLayout> | |
</ScrollView> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment