KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
So, I've followed this particular thread ( How to stop scrolling in a Gallery Widget? ) yet I am unable to get it to work properly. I've created a custom MyGallery class extending Gallery. I've added the code in the link above...am I supposed to add <com.example.mygallery to the XML file? If so, do I also add the import to the java file or is this not needed because of the XML file? I'm so very confused. I want to simply make the gallery move one image at a time per fling. XML file: <?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" android:background="@drawable/carlot_background" > <com.gallerytest.mygallery android:id="@+id/thisgallery" android:gravity="center" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> mygallery.java: package com.gallerytest; import android.content.Context; import android.util.AttributeSet; import android.view.KeyEvent; import android.view.MotionEvent; import android.widget.Gallery; public class mygallery extends Gallery { public mygallery(Context ctx, AttributeSet attrSet) { super(ctx); // TODO Auto-generated constructor stub } private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2){ return e2.getX() > e1.getX(); } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY){ int kEvent; if(isScrollingLeft(e1, e2)){ //Check if scrolling left kEvent = KeyEvent.KEYCODE_DPAD_LEFT; } else{ //Otherwise scrolling right kEvent = KeyEvent.KEYCODE_DP
Tags (comma-separated)
Save Edits
Cancel