0

각 텍스트 폭은 화면의 반 너비입니다. 사용자가 스크롤 제스처를 사용하여이 텍스트 뷰를 함께 이동할 수있게하고 싶습니다. 맨 왼쪽에있는 텍스트 뷰가 화면 외부로 이동하면 세 번째 텍스트 뷰 옆의 맨 오른쪽으로 이동합니다. 그래서 저는 일종의 끝없는 스크롤러 시스템을 만들고 싶습니다.다른 텍스트 뷰 옆에있는 텍스트 뷰 이동하기

그러나 아래 코드를 사용하면 스크롤 할 때 화면 사이에 간격이 생기며 화면 간격의 폭은 스크롤 속도에 의존 할 것으로 생각됩니다. 여기

문제의 스크린 샷에 대한 링크입니다 : http://postimg.org/image/bnl0dqsgd/

현재 내가 한 방향으로 만 스크롤을 구현했습니다.

XML :

다음 onScroll 메소드이어서

public void InitTimeView() { 

    year_views = new BorderedTextView[3]; 
    year_views[0] = (BorderedTextView) findViewById(R.id.btvYear1); 
    year_views[1] = (BorderedTextView) findViewById(R.id.btvYear2); 
    year_views[2] = (BorderedTextView) findViewById(R.id.btvYear3); 

    // Acquire display size 
    display = getWindowManager().getDefaultDisplay(); 
    size = new Point(); 
    display.getSize(size); 
    int year_width = size.x/2; 

    year_views[0].setWidth(year_width); 
    year_views[1].setWidth(year_width); 
    year_views[2].setWidth(year_width); 

    // This is done, because when scrolling, the third view which in the beginning is off-screen, could not be seen 
    RelativeLayout relLayout = (RelativeLayout) findViewById(R.id.rel_layout); 
    relLayout.getLayoutParams().width = year_width * 4; 
    relLayout.invalidate(); 
} 

:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/rel_layout" 
    android:layout_width="100dp" 
    android:layout_height="wrap_content" 
    android:clipChildren="false" 
    android:clipToPadding="false"> 

<com.app.healthview.BorderedTextView 
    android:id="@+id/btvYear1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:background="@color/YearColor1" 
    android:maxLines="1" 
    android:text="2012" /> 

<com.app.healthview.BorderedTextView 
    android:id="@+id/btvYear2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:layout_alignParentTop="true" 
    android:layout_toRightOf="@+id/btvYear1" 
    android:background="@color/YearColor2" 
    android:maxLines="1" 
    android:text="2013" /> 

<com.app.healthview.BorderedTextView 
    android:id="@+id/btvYear3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@color/YearColor1" 
    android:layout_alignParentTop="true" 
    android:layout_toRightOf="@+id/btvYear2" 
    android:gravity="center" 
    android:maxLines="1" 
    android:text="2014" /> 

</RelativeLayout> 

그럼 I 콘텐츠보기를 설정 한 후에 호출되는 함수의 뷰를 초기화

public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { 
    // intCurrYearMember is public, it stores the view that is next to be moved 
    // intRightYearMember; intCurrYearMember is located right to this view. 
    switch(intCurrYearMember) { 
    case 0: 
     intRightYearMember = 2; 
    case 1: 
     intRightYearMember = 0; 
    case 2: 
     intRightYearMember = 1; 
    } 

    // Move the views 
    for (TextView textview : year_views) { 
     textview.setX(textview.getX() - (distanceX/2)); 
    } 

    // Check if the view most left is now too far on left, and move it if needed to far right 
    if ((year_views[intCurrYearMember].getX() + year_views[intCurrYearMember].getWidth()) <= 0) { 
     // Is the problem here perhaps? 
     year_views[intCurrYearMember].setX(year_views[intRightYearMember].getRight()); 
     intPreviousMember = intCurrYearMember; 
     if (intCurrYearMember < 2) 
      intCurrYearMember++; 
     else 
      intCurrYearMember = 0; 
    } 

    return true; 
} 

코드에서 볼 수 있듯이, 제 아이디어는 1 년 스크롤러를 만드는 것입니다. 만약 누군가가 어떻게 더 좋은 아이디어를 가지고 있다면, 당신의 조언을 듣게되어 기쁩니다!

제 질문은 텍스트 뷰 사이에 왜 간격이 있습니까?

답변

0

나는이 일을 전혀 제안하지 않을 것입니다. 이러한 것들을 위해 수평 스 와이프를 사용하는 것은 플랫폼을 표준으로 사용하는 것이 아니며, 이미 테스트를 마친 후 이것을 개발하는 데 시간을 낭비하고 쉽게 사용할 수있는 Pickers과 같은 예쁜 Android 구성 요소를 낭비하는 것입니다.

가로 스 와이프 동작은 일반적으로 메뉴 드로어, 뷰 페이저 또는 다른 기능에 대해 저장됩니다.

+0

답장을 보내 주셔서 감사합니다. 그러나 만약 내가 이것을 시스템에서 구현한다면, 그 날짜는 스크롤러 아래 그려지는 그래프의 x 값이 될 것인가? 따라서 스크롤러는 선 그래프의 가로 축으로 생각할 수 있습니다 (아직 구현하지 않았습니다). 그럼 나는 정말로 가로 스 와이프가 필요합니다. – user2891883