Showing posts with label ScrollView. Show all posts
Showing posts with label ScrollView. Show all posts

Monday, October 28, 2013

ViewPager android Fact and constraint about offscreen page limit

ViewPager inbuilt swipe animation is very good. ViewPager exist for a reason with HorizontalScrollView(Which scroll the content in same manner but different methodologies). ViewPager used for swiping content on the base of keep ready next content to be swipe. And its whole limitation and strength, which developer feels some times, lie in that.

How many (i.e Minimum and Maximum) page of ViewPager may be preloaded?

setOffscreenPageLimit(1); decide how many page to be preloaded. As i am not sure about what is the maximum limit for it but minimum is 1. setting off screen page limit to 0 does nothing except throwing  warning in LogCat Requested offscreen page limit 0 too small; defaulting to 1.  Its because ViewPager is based on concept of keep ready next page to be loaded. ViewPager can not the page which not exist still. Android documentation of ViewPager clearly. But most developer feels its not what they required. Then you have option with some work around there but you can not change ViewPager behavior.

Some people argue that they want to load empty instance of fragment as part of child of ViewPager then later on full content. You are free to do  but you will be solely responsible to handle its complications.

onPageListner gives you a way but its bit of tricky to handle.


I absolutely agree with ViewPager's documentation. There must be some content exist before swiping it down. You can use an in out animation if you do not want to customize ViewPager. But being with Adapter, ViewPager allow you to recyling of View

Monday, April 16, 2012

Creating HorizontalScrollView in Android

Today i am going to describing a powerful tool of android, Horizontal Listview with complete source in the end.
Horizontal ListView sometimes is very useful and it save our day. HorizontalScrollView is nothing but a widget, If you add more element than its visible area then it start scrolling horizontally. Bit main disadvantage is that you can not perform click on the base of position quite easily

If you need some explanation then read complete step else download code with link in the end and play with it

Step 1) Create one new Project name HorizontalListviewDemo

Step 2) Change your main activity to as follow class

 package com.ahmad;  
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;
public class SecondActivity extends Activity implements OnClickListener {
Button btn1, btn2, btn3, btn4;
public LinearLayout middle;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn1 = (Button) findViewById(R.id.btn1);
btn1.setOnClickListener(this);
btn2 = (Button) findViewById(R.id.btn2);
btn2.setOnClickListener(this);
btn3 = (Button) findViewById(R.id.btn3);
btn3.setOnClickListener(this);
try {
btn4 = (Button) findViewById(R.id.btn4);
btn4.setOnClickListener(this);
} catch (Exception e) {
e.getMessage();
}
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.btn1) {
Toast.makeText(this, "Second Act Btn1 Clicked", Toast.LENGTH_LONG)
.show();
} else if (v.getId() == R.id.btn2) {
Toast.makeText(this, "Second Act Btn 2 Clicked", Toast.LENGTH_LONG)
.show();
} else if (v.getId() == R.id.btn3) {
Toast.makeText(this, "Second Act Btn 3 Clicked", Toast.LENGTH_LONG)
.show();
} else if (v.getId() == R.id.btn4) {
Toast.makeText(this, "Second Act Btn 4 Clicked", Toast.LENGTH_LONG)
.show();
}
}
}
Step 3)Make one Layout and add HorizontalListview and some content inside

  
Now enjoy after running it.complete source link is below.See more article on ListView in blog tag Android ListView
                                                          Download Complete Project
Posting Lama ►
 

Copyright 2013 Tutorials For Newbie: ScrollView Template by CB Blogger Template. Powered by Blogger