ScrollView implements seamless link rolling view and scrollview
Source code download
Code implementation:
-(Void) createView {self. scrollView = [[UIScrollView alloc] initWithFrame: CGRectMake (0, 0 + 64,320,230)]; self. scrollView. backgroundColor = [UIColor yellowColor]; // locks the sliding direction _ scrollView. directionalLockEnabled = NO; _ scrollView. contentSize = CGSizeMake (320 * (number + 2), 240); // bounce effect _ scrollView. bounces = NO; _ scrollView. showsHorizontalScrollIndicator = NO; _ scrollView. showsVerticalScrollIndicator = NO; _ scrollView. pagingEnabled = YES; _ scrollView. delegate = self; // Add imageView for (int I = 0; I <number + 2; I ++) {self. testImageView = [[UIImageView alloc] initWithFrame: CGRectMake (320 * I + 3, 3,314,224)]; _ testImageView. userInteractionEnabled = YES; _ testImageView. backgroundColor = [UIColor redColor]; _ testImageView. tag= 100 + I; [self. scrollView addSubview: _ testImageView];} // The initial offset. The first image _ scrollView is displayed. contentOffset = CGPointMake (320, 0); [self. view addSubview: _ scrollView]; // Add an image [self addImage]; self. pageControl = [[UIPageControl alloc] initWithFrame: CGRectMake (90,270,250, 15)]; self. pageControl. numberOfPages = number; _ pageControl. backgroundColor = [UIColor clearColor]; // page number control point color _ pageControl. pageIndicatorTintColor = [UIColor grayColor]; _ pageControl. currentPageIndicatorTintColor = [UIColor cyanColor]; // Add the target event [self. pageControl addTarget: self action: @ selector (handlePageControlAction :) forControlEvents: UIControlEventValueChanged]; [self. view addSubview: self. pageControl]; [self addTimer]; self. YJFImageView = [[UIImageView alloc] initWithFrame: CGRectMake (0,235 + 64,320,568-240-64)]; self. YJFImageView. image = LOADIMAGE (@ "background image", @ "jpg"); [self. view addSubview: _ YJFImageView]; UILabel * YJFLabel = [[UILabel alloc] initWithFrame: CGRectMake (20,100,280, 60)]; YJFLabel. text = @ "Email: summer2014mht@sina.com"; YJFLabel. textColor = [UIColor blackColor]; YJFLabel. textAlignment = NSTextAlignmentCenter; YJFLabel. font = [UIFont systemFontOfSize: 16]; [self. YJFImageView addSubview: YJFLabel];}-(void) addImage {for (int I = 0; I <number; I ++) {UIImageView * picImageView = (UIImageView *) [self. view viewWithTag: 101 + I]; picImageView. image = LOADIMAGE (self. imageNameArray [I], @ "jpg");} UIImageView * picImageViewFirst = (UIImageView *) [self. scrollView viewWithTag: 100 + number + 1]; picImageViewFirst. image = LOADIMAGE (self. imageNameArray [number-1], @ "jpg"); UIImageView * picImageViewLast = (UIImageView *) [self. scrollView viewWithTag: 100 + number + 1]; picImageViewLast. image = LOADIMAGE (self. imageNameArray [0], @ "jpg");} // pageControl click the corresponding event-(void) handlePageControlAction :( UIPageControl *) sender {NSInteger currentPage = _ pageControl. currentPage; CGPoint offsetPoint = CGPointMake (currentPage * 320, 0); // scroll scrollView [self. scrollView setContentOffset: offsetPoint animated: YES];} // Add a timer to implement a carousel image-(void) addTimer {[nst1_scheduledtimerwithtimeinterval: 1.5 target: self selector: @ selector (runTimer) userInfo: nil repeats: YES];} // timer response method-(void) runTimer {CGFloat x = _ scrollView. contentOffset. x; [_ scrollView setContentOffset: CGPointMake (x + 320, 0) animated: YES] ;}# pragma mark-ScrollView Delegate // change pageControl with view-(void) scrollViewDidScroll :( UIScrollView *) scrollView {if (0 = scrollView. contentOffset. x) {[scrollView setContentOffset: CGPointMake (320 * number, 0) animated: NO];} else if (number + 1) * 320) = scrollView. contentOffset. x) {[scrollView setContentOffset: CGPointMake (320, 0) animated: NO];} self. pageControl. currentPage = scrollView. contentOffset. x/320-1;}-(void) customizedNavigationBar {self. navigationItem. title = @ "Carousel image demo ";}
In android programming, how does one implement Page scrolling using ScrollView? How to Implement
1L positive solution. It is to wrap a layer of ScrollView outside all the controls in your current xml, so that all the displayed content in the ScrollView can be viewed in a rolling manner.
How can I determine to scroll the Scrollview scroll to the bottom?
I checked a lot of information on the Internet, most of which were the same. I learned a more reliable one and put it in my own project. what I realized was to add the listview IN THE Scrollview, note that because there is a conflict between the two scroll bars, the listview must be rewritten by itself. The Code has the truth: public class CompleteListView extends ListView {public CompleteListView (Context context, AttributeSet attrs) {super (context, attrs);} public CompleteListView (Context context) {super (context);} public CompleteListView (Context context, AttributeSet attrs, int defStyle) {super (context, Trs, defStyle) ;}@ Override public void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {int expandSpec = MeasureSpec. makeMeasureSpec (Integer. MAX_VALUE> 2, MeasureSpec. AT_MOST); super. onMeasure (widthMeasureSpec, expandSpec) ;}}note that the onMeasure (int widthMeasureSpec, int heightMeasureSpec) method is used to resolve the conflict. The judgment method is: implents OnTouchListener @ Override public boolean onTouch (View v, MotionEvent event) {switch (event. getAction () {case MotionEvent. ACTION_DOWN: break; case MotionEvent. ACTION_MOVE: index ++; break; default: break;} if (event. getAction () = MotionEvent. ACTION_UP & index> 0) {index = 0; mLastY = scrollView. getScrollY (); // value to mLastY // alllinear is the linearlayout layout included in scrollview if (mLastY = (alllinear. getHeight ()-scrollView. getHeight () {// TODO // slide to the bottom, what you want to do} return false;} Sorry, if you do not need to add a few very important steps, you will find no effect: 1: Define Scrollview scrollview; 2: Add a member variable: int index to optimize the sliding listening; 3: findviewById needless to say, 4: scrollView. setOnTouchListener (this); // very important ··················