2017-01-17 5 views
0

여러 개의 텍스트보기가있는 가로 스크롤보기가 있습니다. 상단 레이아웃에는 포인터가 있고 포인터 아래에 각각의 파편이 나타나도록 다른 텍스트보기가 있습니다. 지금은 자유롭게 스크롤되며 2 개의 텍스트보기 사이에서 멈출 수 있습니다. 내가 원하는 것은 왼쪽 또는 오른쪽으로 쓸어 넘기 때마다 일정량을 스크롤하여 위의 포인터 중앙에 텍스트보기가 표시되도록하는 것입니다. 내가 여기에 상대 레이아웃에 넣어 및가로 스크롤보기에서 한 번 스 와이프하여 일정 금액 스크롤

은에 대한 XML입니다 그것을

<LinearLayout 
    android:id="@+id/ic_layout" 
    android:layout_width="match_parent" 
    android:orientation="horizontal" 
    android:layout_height="20dp"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="20dp" 
     android:src="@drawable/arrow"/> 

</LinearLayout> 

<HorizontalScrollView 
    android:id="@+id/HorizontalScrollView1" 
    android:layout_width="300dp" 
    android:layout_height="75dp" 
    android:background="#FFF" 
    android:scrollbars="none" 
    android:fillViewport="false" 
    android:layout_below="@+id/ic_layout" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginLeft="100dp" 
    android:layout_marginRight="100dp"> 

    <LinearLayout 
     android:id="@+id/imgLayout1" 
     android:layout_width="wrap_content" 
     android:layout_height="100dp" 
     android:orientation="horizontal" 
     android:gravity="center"> 

     <TextView 
      android:layout_width="130dp" 
      android:layout_height="40dp" 
      android:paddingLeft="120dp" 
      android:paddingRight="10dp" /> 

     <TextView 
      android:layout_width="100dp" 
      android:layout_height="40dp" 
      android:text="Random Crap1" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp"/> 
     <TextView 
      android:layout_width="100dp" 
      android:layout_height="40dp" 
      android:text="Random Crap2" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp"/> 
     <TextView 
      android:layout_width="100dp" 
      android:layout_height="40dp" 
      android:text="Random Crap3" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp"/> 

     <TextView 
      android:layout_width="100dp" 
      android:layout_height="40dp" 
      android:text="Random Crap4" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp"/> 

     <TextView 
      android:layout_width="100dp" 
      android:layout_height="40dp" 
      android:text="Random Crap5" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp"/> 

     <TextView 
      android:layout_width="100dp" 
      android:layout_height="40dp" 
      android:text="Random Crap6" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp"/> 

     <TextView 
      android:layout_width="100dp" 
      android:layout_height="40dp" 
      android:text="Random Crap7" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp"/> 

     <TextView 
      android:layout_width="70dp" 
      android:layout_height="40dp" 
      android:paddingLeft="10dp" 
      android:paddingRight="70dp"/> 


    </LinearLayout> 


</HorizontalScrollView> 

답변

0

따라

final HorizontalScrollView YourHorizontalScrollView = (HorizontalScrollView) findViewById(R.id.YourHorizontalScrollView); 

YourHorizontalScrollView.post(new Runnable() { 

    @Override 
    public void run() { 
     final TextView YourTextView = (TextView) findViewById(R.id.yourTextView); 
     int scrollTo = 0; 
     final int count = ((LinearLayout) YourHorizontalScrollView.getChildAt(0)) 
       .getChildCount(); 
     for (int i = 0; i < count; i++) { 
      final View child = ((LinearLayout) YourHorizontalScrollView.getChildAt(0)) 
        .getChildAt(i);     
      if (child != yourTextView) { 
       scrollTo += child.getWidth(); 
      } else { 
       break; 
      } 
     } 
     YourHorizontalScrollView.scrollTo(scrollTo, 0); 
    } 

}); 

희망이 : 코드 아래에 특정 량의 사용에 수평있는 ScrollView를 스크롤

도와 줘.

0

수평 스크롤 대신 ViewPager를 사용해야합니다. 매번 고정 스크롤을 할 때 유용합니다. 더 나은 환경을 위해 ViewPager의 높이를 고정하십시오. ViewPager 용 맞춤 어댑터 사용

public class CustomViewPagerImageAdapterPC extends PagerAdapter { 

@Override 
public float getPageWidth(int position) { 
    // TODO Auto-generated method stub 
    //return super.getPageWidth(position); 
    return 0.4f; 
}