Created
September 26, 2015 07:46
-
-
Save nowke/3d1ed43e53b1df463382 to your computer and use it in GitHub Desktop.
Final DetailActivity.java - with parallax image scroll
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
package in.nowke.appbarmiddlelayout; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.support.v7.widget.Toolbar; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import android.view.ViewTreeObserver; | |
import android.widget.ImageView; | |
import com.emilsjolander.components.StickyScrollViewItems.StickyScrollView; | |
public class DetailActivity extends AppCompatActivity { | |
private Toolbar toolbar; | |
private StickyScrollView scrollView; | |
private ImageView imageView; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_detail); | |
toolbar = (Toolbar) findViewById(R.id.toolbar); | |
setSupportActionBar(toolbar); | |
getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
getSupportActionBar().setDisplayShowTitleEnabled(false); | |
imageView = (ImageView) findViewById(R.id.imageView); | |
scrollView = (StickyScrollView) findViewById(R.id.scrollView); | |
scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { | |
@Override | |
public void onScrollChanged() { | |
int scrollY = scrollView.getScrollY(); | |
imageView.setTranslationY(scrollY/2); | |
} | |
}); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.menu_detail, menu); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment