Pages

Showing posts with label flipper. Show all posts
Showing posts with label flipper. Show all posts

Wednesday, April 20, 2016

Using View Flipper in Android

Suppose you want to display a news bar in your activity. this news bar displays a single news item at a time then flips and shows next item and so on, then your choice would be Androids ViewFlipper.

ViewFlipper inherits from frame layout, so it displays a single view at a time.

consider this layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android_orientation="vertical"
android_layout_width="fill_parent"
android_layout_height="fill_parent"
>
<TextView
android_layout_width="fill_parent"
android_layout_height="wrap_content"
android_text="@string/hello"
/>
<Button
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_text="Flip"
android_id="@+id/btn"
android_onClick="ClickHandler"
/>
<ViewFlipper
android_layout_width="fill_parent"
android_layout_height="fill_parent"
android_id="@+id/flip"
>
<TextView
android_layout_width="fill_parent"
android_layout_height="wrap_content"
android_text="Item1"
/>
<TextView
android_layout_width="fill_parent"
android_layout_height="wrap_content"
android_text="Item2"
/>
<TextView
android_layout_width="fill_parent"
android_layout_height="wrap_content"
android_text="Item3"
/>
</ViewFlipper>
</LinearLayout>


just a ViewFlipper container that contains three text views

now we want to flip the views when the button is clicked
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

btn=(Button)findViewById(R.id.btn);
flip=(ViewFlipper)findViewById(R.id.flip);

}

public void ClickHandler(View v)
{

flip.showNext();

}

if we want to flip in reverese direction we could use
flip.showPrevious() instead

we can add animations to the child views when they appear or disappear:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

btn=(Button)findViewById(R.id.btn);
flip=(ViewFlipper)findViewById(R.id.flip);
//when a view is displayed
flip.setInAnimation(this,android.R.anim.fade_in);
//when a view disappears
flip.setOutAnimation(this, android.R.anim.fade_out);
}

we can also set the ViewFlipper to flip views automatically when the button is clicked:
public void ClickHandler(View v)
{


//specify flipping interval
flip.setFlipInterval(1000);
flip.startFlipping();
}

we can stop the flipping by calling flip.stopFlipping(); method.

or we can set the flipper to flip autommatically when the activity starts
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

btn=(Button)findViewById(R.id.btn);
flip=(ViewFlipper)findViewById(R.id.flip);
flip.setInAnimation(this,android.R.anim.fade_in);
flip.setOutAnimation(this, android.R.anim.fade_out);
flip.setFlipInterval(1000);
flip.setAutoStart(true);

}
Read More..

Saturday, April 16, 2016

Android Developers Backstage Episode 8 Volley



In this episode, the second in a bizarrely and completely unplanned series on Play Store technology, Tor Norbye and Chet Haase are joined by Ficus Kirkpatrick from the Play Store team (and from many other Android projects from the early days). Listen in to hear what Volley is for and how you can use it to simplify your network requests and bitmap download/caching code.

Relevant links:
Volley: https://android.googlesource.com/platform/frameworks/volley/
Volley email list: https://groups.google.com/forum/#!forum/volley-users
Gson adapter for Volley: https://gist.github.com/ficusk/5474673

Subscribe to the podcast at http://feeds.feedburner.com/blogspot/AndroidDevelopersBackstage?.
Or download directly at http://storage.googleapis.com/androiddevelopers/android_developers_backstage/Android%20Developers%20Backstage%20Ep%208%20Volley.mp3
Read More..