2

I have a ScrollView and GridView in it, I want to put a TextView on top of GridView but it must not be seen until user scrolls to it. I thought about negative margins but I couldn't find a solution how to use scroll to get this view when on negative margin.

So basicaly : The only seen thing should be gridView, but when user is on top of gridView and pulls up, he should see a TextView.

edit: the whole point of this is that I want to made pull-to-refresh out of this. I don't want to use popular on the internet libary because it doesn't work way I want.

EDIT 2:

I got the answer but it is not fully what I try to achieve. I want to smoothly show hidden TextView (just like in pull-to-refresh solutions) and setVisibility makes it quick and without any smoothnes. Here is my code :

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>

and code:

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) {
                                }
                            }
                        }
                    });
filipp.kowalski
  • 5,495
  • 7
  • 27
  • 45

3 Answers3

11

you can do this by using setOnScrollListener for GridView as:

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;
       }
    }
 });

EDIT 1

for smoothness try this one (not tested)

 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;
Qadir Hussain
  • 8,721
  • 13
  • 89
  • 124
9

Place both your GridView and your TextView inside a LinearLayout (or RelativeLayout)

Then have the ScrollView only contain your Linear/Relative layout.

To hide textview, use findViewById(R.id.textviewId).setVisibility(View.GONE); (use View.VISIBLE to set it visible again).

Simon Forsberg
  • 13,086
  • 10
  • 64
  • 108
0

There is an option in the xml for visibility. Click the TextView and then change that to Invisible or Gone.