如何隐藏TextView并仅在滚动时显示

fil*_*ski 2 android scrollview

我有一个ScrollView和GridView,我想在GridView上放置一个TextView,但在用户滚动到它之前一定不能看到它.我想到了负边距,但我找不到解决方案如何在负边距时使用滚动来获取此视图.

所以基本上:唯一看到的应该是gridView,但是当用户位于gridView之上并且拉起时,他应该看到一个TextView.

编辑:这一点的重点在于我想要从中进行拉动式刷新.我不想在互联网图书馆中使用流行版,因为它不能按我想要的方式使用.

编辑2:

我得到了答案,但这并不是我试图实现的目标.我想平滑地显示隐藏的TextView(就像在pull-to-refresh解决方案中一样)和setVisibility使它快速且没有任何smoothnes.这是我的代码:

XML:

<com.tas.android.quick.ui.controls.LockableScrollView
        android:id="@+id/scrollView"
        android:fillViewport="true"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TextView 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/pullText"
                android:text="some text" />

            <com.tas.android.quick.ui.controls.ExpandableGridView
                android:id="@+id/gridview"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:clipToPadding="false"
                android:drawSelectorOnTop="true"
                android:fadingEdge="none"
                android:gravity="top"
                android:horizontalSpacing="@dimen/image_grid_hspacing"
                android:listSelector="@drawable/selector_shadow"
                android:numColumns="@integer/grid_num_cols"
                android:paddingBottom="50dp"
                android:scrollbarAlwaysDrawVerticalTrack="false"
                android:scrollbars="none"
                android:scrollingCache="true"
                android:smoothScrollbar="false"
                android:stretchMode="columnWidth"
                android:verticalSpacing="@dimen/image_grid_vspacing"
                android:visibility="visible" />
        </LinearLayout>
    </com.tas.android.quick.ui.controls.LockableScrollView>
Run Code Online (Sandbox Code Playgroud)

和代码:

textview = (TextView) findViewById(R.id.pullText);
        textview.setVisibility(View.VISIBLE);

        scrollView = (LockableScrollView) findViewById(R.id.scrollView);

        scrollView.setScrollingEnabled(false);

...

gridView.setOnScrollListener(new OnScrollListener() {
                        @Override
                        public void onScrollStateChanged(AbsListView view, int scrollState) {
                            switch(scrollState) {
                            case 2: // SCROLL_STATE_FLING 
                                //hide button here
                                textview.setVisibility(View.VISIBLE);
                                break;

                            case 1: // SCROLL_STATE_TOUCH_SCROLL 
                                //hide button here
                                textview.setVisibility(View.GONE);
                                break;

                            case 0: // SCROLL_STATE_IDLE 
                                //show button here
                                textview.setVisibility(View.GONE);
                                break;
                            }
                        }

                        @Override
                        public void onScroll(AbsListView view, int firstVisibleItem,
                                int visibleItemCount, int totalItemCount) {
                                }
                            }
                        }
                    });
Run Code Online (Sandbox Code Playgroud)

Qad*_*ain 12

你可以使用GridView的setOnScrollListener作为:

gridview.setOnScrollListener(new OnScrollListener() {

   @Override
    public void onScroll(AbsListView view, int firstVisibleItem,
              int visibleItemCount, int totalItemCount) {

  }

@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
        // TODO Auto-generated method stub
  switch(scrollState) {
    case 2: // SCROLL_STATE_FLING 
    //hide button here
    yourTextView.setVisibility(View.GONE);
    break;

    case 1: // SCROLL_STATE_TOUCH_SCROLL 
    //hide button here
    yourTextView.setVisibility(View.GONE);
    break;

    case 0: // SCROLL_STATE_IDLE 
    //show button here
    yourTextView.setVisibility(View.VISIBLE);
    break;

        default:
     //show button here
    btn.setVisibility(View.VISIBLE);
    break;
       }
    }
 });
Run Code Online (Sandbox Code Playgroud)

编辑1

为了顺利尝试这个(未测试)

 switch(scrollState) {
case 2: // SCROLL_STATE_FLING 

Animation animation = new TranslateAnimation(0,0,0,1000);
animation.setDuration(1000);
mytextview.startAnimation(animation);
mytextview.setVisibility(View.GONE);

break;

case 1: // SCROLL_STATE_TOUCH_SCROLL 
//hide button here
Animation animation = new TranslateAnimation(0,0,0,1000);
animation.setDuration(1000);
mytextview.startAnimation(animation);
yourTextView.setVisibility(View.GONE);
break;

case 0: // SCROLL_STATE_IDLE 
//show button here
Animation animation = new TranslateAnimation(0,0,0,1000);
animation.setDuration(1000);
mytextview.startAnimation(animation);
yourTextView.setVisibility(View.VISIBLE);
break;

    default:
 //show button here
Animation animation = new TranslateAnimation(0,0,0,1000);
animation.setDuration(1000);
mytextview.startAnimation(animation);
yourTextView.setVisibility(View.VISIBLE);
break;
Run Code Online (Sandbox Code Playgroud)


Sim*_*erg 9

将GridView和TextView放在LinearLayout(或RelativeLayout)中

然后让ScrollView仅包含您的线性/相对布局.

要隐藏findViewById(R.id.textviewId).setVisibility(View.GONE);文本视图,请使用(使用View.VISIBLE将其再次设置为可见).