am d038afd3
: am 7074f324
: Merge "docs: Fixed ViewPager animation tutorial. Bug: 12815243" into klp-docs
* commit 'd038afd39874238357a5ca9621921542f57db7a1': docs: Fixed ViewPager animation tutorial. Bug: 12815243
This commit is contained in:
@ -63,11 +63,11 @@ following files for the code implementation:</p>
|
|||||||
contains a text view to display some text:
|
contains a text view to display some text:
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<com.example.android.animationsdemo.ScrollView
|
<!-- fragment_screen_slide_page.xml -->
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/content"
|
android:id="@+id/content"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent" >
|
||||||
|
|
||||||
<TextView style="?android:textAppearanceMedium"
|
<TextView style="?android:textAppearanceMedium"
|
||||||
android:padding="16dp"
|
android:padding="16dp"
|
||||||
@ -75,10 +75,11 @@ following files for the code implementation:</p>
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/lorem_ipsum" />
|
android:text="@string/lorem_ipsum" />
|
||||||
|
</ScrollView>
|
||||||
</com.example.android.animationsdemo.ScrollView>
|
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
<p>Define also a string for the contents of the fragment.</p>
|
||||||
|
|
||||||
<h2 id="fragment">Create the Fragment</h2>
|
<h2 id="fragment">Create the Fragment</h2>
|
||||||
<p>Create a {@link android.support.v4.app.Fragment} class that returns the layout
|
<p>Create a {@link android.support.v4.app.Fragment} class that returns the layout
|
||||||
that you just created in the {@link android.app.Fragment#onCreateView onCreateView()}
|
that you just created in the {@link android.app.Fragment#onCreateView onCreateView()}
|
||||||
@ -87,6 +88,8 @@ that you just created in the {@link android.app.Fragment#onCreateView onCreateVi
|
|||||||
|
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
...
|
||||||
public class ScreenSlidePageFragment extends Fragment {
|
public class ScreenSlidePageFragment extends Fragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -111,6 +114,7 @@ fragment class that you created earlier.
|
|||||||
<p>To begin, create a layout that contains a {@link android.support.v4.view.ViewPager}:</p>
|
<p>To begin, create a layout that contains a {@link android.support.v4.view.ViewPager}:</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
|
<!-- activity_screen_slide.xml -->
|
||||||
<android.support.v4.view.ViewPager
|
<android.support.v4.view.ViewPager
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/pager"
|
android:id="@+id/pager"
|
||||||
@ -133,6 +137,9 @@ fragment class that you created earlier.
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.app.FragmentManager;
|
||||||
|
...
|
||||||
public class ScreenSlidePagerActivity extends FragmentActivity {
|
public class ScreenSlidePagerActivity extends FragmentActivity {
|
||||||
/**
|
/**
|
||||||
* The number of pages (wizard steps) to show in this demo.
|
* The number of pages (wizard steps) to show in this demo.
|
||||||
@ -153,11 +160,11 @@ public class ScreenSlidePagerActivity extends FragmentActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_screen_slide_pager);
|
setContentView(R.layout.activity_screen_slide);
|
||||||
|
|
||||||
// Instantiate a ViewPager and a PagerAdapter.
|
// Instantiate a ViewPager and a PagerAdapter.
|
||||||
mPager = (ViewPager) findViewById(R.id.pager);
|
mPager = (ViewPager) findViewById(R.id.pager);
|
||||||
mPagerAdapter = new ScreenSlidePagerAdapter(getFragmentManager());
|
mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
|
||||||
mPager.setAdapter(mPagerAdapter);
|
mPager.setAdapter(mPagerAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,9 +231,9 @@ call {@link android.support.v4.view.ViewPager#setPageTransformer setPageTransfor
|
|||||||
<code>ZoomOutPageTransformer</code>, you can set your custom animations
|
<code>ZoomOutPageTransformer</code>, you can set your custom animations
|
||||||
like this:</p>
|
like this:</p>
|
||||||
<pre>
|
<pre>
|
||||||
ViewPager pager = (ViewPager) findViewById(R.id.pager);
|
ViewPager mPager = (ViewPager) findViewById(R.id.pager);
|
||||||
...
|
...
|
||||||
pager.setPageTransformer(true, new ZoomOutPageTransformer());
|
mPager.setPageTransformer(true, new ZoomOutPageTransformer());
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
|
||||||
@ -257,8 +264,8 @@ sections for examples and videos of a {@link android.support.v4.view.ViewPager.P
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
|
public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
|
||||||
private static float MIN_SCALE = 0.85f;
|
private static final float MIN_SCALE = 0.85f;
|
||||||
private static float MIN_ALPHA = 0.5f;
|
private static final float MIN_ALPHA = 0.5f;
|
||||||
|
|
||||||
public void transformPage(View view, float position) {
|
public void transformPage(View view, float position) {
|
||||||
int pageWidth = view.getWidth();
|
int pageWidth = view.getWidth();
|
||||||
@ -332,7 +339,7 @@ in a working page transformer:
|
|||||||
<pre>
|
<pre>
|
||||||
|
|
||||||
public class DepthPageTransformer implements ViewPager.PageTransformer {
|
public class DepthPageTransformer implements ViewPager.PageTransformer {
|
||||||
private static float MIN_SCALE = 0.75f;
|
private static final float MIN_SCALE = 0.75f;
|
||||||
|
|
||||||
public void transformPage(View view, float position) {
|
public void transformPage(View view, float position) {
|
||||||
int pageWidth = view.getWidth();
|
int pageWidth = view.getWidth();
|
||||||
|
Reference in New Issue
Block a user