2016-09-30 4 views
1

scrollview 내부에 scrollview가 있습니다. 항목이 있고 그 중 일부를 화면 맨 위에 고정하고 싶습니다 (scrollableListener와 유사) scrollView에 의존합니다. scrollY. 나는 거의 모든 것을 시도했다.scrollview 내부의 뷰 위치를 변경하여 화면 상단에 고정하는 방법은 무엇입니까?

내 머리글 항목 Y 위치를 0으로 설정하면 위치가 변경되지만 이후에는 scrollView 내부의 첫 번째 항목이됩니다.

header.animate().y(0).setDuration(0).start(); // first attempt 
header.setTop(0); // second attempt 
header.animate().y(mScrollView.getLastItem().getBottom).setDuration(0).start();// third attempt 

PS

내 목표는 내가있는 ScrollView 안에이 library 시도있는 ScrollView 내부 stickyheader 목록 항목을 만드는 것입니다,하지만이 일을하지 않는, 모든 항목은 일반적으로 잘

답변

1

스크롤했다 Android에서 동일한 UI를 구현하는 데는 여러 가지 방법이있을 것이라고 생각합니다.

1) 첫 번째 방법은,이 같은 상대 레이아웃으로 스크롤 뷰를 포장 :

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:text="top here" 
      android:id="@+id/text" 
      /> 

     <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/text" 
      > 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="sample" 
       /> 
     </ScrollView> 
    </RelativeLayout> 

2) 또는 다른 방법은 당신이 두 조각으로 메인 레이아웃을 나눌 수 있습니다, 하나 개의 조각이보기를 표시하는 항상 맨 위에 표시되며 다른 뷰는 스크롤 뷰의 내용을로드합니다.

3)이 포스트는 Android: pin TabLayout to top of Scrollview

에 대한 좋은 참조가 될 수 있습니다
관련 문제