开发者

How to make horizontal scrolling view in android

I Want to make this type of horizontal scrolling , look at pictures

How to make horizontal scrolling view in android

>>>>............................................

How to make horizontal scrolling view in android

XML file saved at res/layout/main.xml: Am i right my main.xml file has worng? I want to use .

   <?xml version="1.0" encoding="utf-8"?>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView  android:id="@+id/imageView1"
    android:layout_width="wrap_content" android:layout_height="200dp">    </ImageView>
   <TextView android:text="Zoo"
    android:id="@+id/PicDescription" android:layout_width="wrap_content"
    android:textSize="40sp" android:layout_height="wrap_content"
    android:layout_gravity="center" android:layout_marginTop="10dp"></TextView>
  <TextView android:text="Z" android:id="@+id/captitalText"
    android:layout_height="wrap_content" android:layout_gravity="center"    android:textSize="100sp"
    android:layout_width="wrap_content" android:layout_marginTop="25dp"></TextView>

XML file saved at res/values/letters.xml:

<?xml version="1.0" encoding="utf-8"?>
resources>
  <string-array name="desc">
    <item>Apple</item>
    <item>Ball</item>
    ...
    <item>Zoo</item>
 </string-array>

 <string-array name="capitalLetter">
    <item>A</item>
    <item>B</item>
    ...
    <item>Z</item>
  </string-array>

What is the code of that Horizontal scrolling action in android. Please give advice, I am the new of the android, I totally confused of that scrolling. I follow this link1 link2 but could not get any idea. Thanks in advance and hope you can solve this.

Edit : Sep 11

Here is my code.It out is when I try to scrolling then change B, when complete scrolling the page the again A becomes. I think, I call when scrolling is complete starting value, am i right?

Give me suggestion what can i do for fix this code.

  public class Test extends Activity {
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
private GestureDetector gestureDetector;
String[] big;
TextView txtbig;
int count=0;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    big = getResources().getStringArray(R.array.capitalLetter);

    gestureDetector = new GestureDetector(new MyGestureDetector());
    View mainview = (View) findViewById(R.id.mainView);

    mainview.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (gestureDetector.onTouchEvent(event)) {
                textChange();
                return true;
            }
            return false;
        }
    });
    //textChange();
}
private void textChange() {
    txtbig = (TextView) findViewById(R.id.b开发者_StackOverflow中文版igText);
    String bigTextString=big[count];
    txtbig.setText(bigTextString);

    count++;

    if(count==big.length)
    {
    count=0;
    }
}
class MyGestureDetector extends SimpleOnGestureListener {
    @Override

    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {

        Intent intent = new Intent(Test.this.getBaseContext(),Test.class);
         //textChange();
        if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) {
            //textChange();
            return false;
        }

        // right to left swipe
        if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
                && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {                textChange();
            startActivity(intent);
            Test.this.overridePendingTransition(
                    R.anim.slide_in_right, R.anim.slide_out_left);

            return true;
            // right to left swipe
        } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
                && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            // startActivity(intent);
            // textChange();
            Test.this.overridePendingTransition(
                    R.anim.slide_in_left, R.anim.slide_out_right);
        }

        return false;
    }
    @Override
    public boolean onDown(MotionEvent e) {
        return true;
    }
}

}


Android has a several built-in HorizontalScrollView and reading from your question, it looks like you just want to enable scrolling and able to lock each page for your selection.

The ViewPager might just be what you need in order to implement that. You could read about that module from the Android Developer Blogspot. See the picture below (taken from that site) which seems to have similar function to what you want to achieve.

How to make horizontal scrolling view in android


This should be what you're looking for :) http://code.google.com/p/android-ui-utils/downloads/detail?name=CarouselExample.zip&can=1&q=

Alternatively (very.... alternatively), you could create a web app using Sencha Touch and use PhoneGap to run it on your android device but that may be a little overkill.


You can use Android v4 Compatibility package. Check this link


my kind advice is please keep the button "next" for that set the Action as start Activity() call the same activity and set flage count =1 , set "a" count =2 , set "B"...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜