Created
August 1, 2014 12:39
-
-
Save diegogurgel/3d5c1a97ee49d364bd70 to your computer and use it in GitHub Desktop.
Test listview with background view and simple scroll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| android:background="#000" | |
| tools:context="${relativePackage}.${activityClass}" > | |
| <View | |
| android:layout_width="fill_parent" | |
| android:layout_height="fill_parent" | |
| android:background="#ff9900" | |
| /> | |
| <ListView | |
| android:id="@+id/listView1" | |
| android:layout_width="fill_parent" | |
| android:layout_height="fill_parent" | |
| android:background="@android:color/transparent"> | |
| </ListView> | |
| </RelativeLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <TextView xmlns:android="http://schemas.android.com/apk/res/android" | |
| android:layout_width="fill_parent" | |
| android:layout_height="fill_parent" | |
| android:padding="10dp" | |
| android:textSize="20sp" | |
| android:background="#fff" > | |
| </TextView> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.diegogurgel.swipelistviewmap; | |
| import android.app.Activity; | |
| import android.graphics.Color; | |
| import android.os.Bundle; | |
| import android.util.Log; | |
| import android.view.MotionEvent; | |
| import android.view.View; | |
| import android.view.View.OnTouchListener; | |
| import android.widget.AbsListView; | |
| import android.widget.AbsListView.OnScrollListener; | |
| import android.widget.ArrayAdapter; | |
| import android.widget.ListView; | |
| import android.widget.TextView; | |
| public class MainActivity extends Activity { | |
| int scrollState=0; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| ListView lv = (ListView) findViewById(R.id.listView1); | |
| final TextView invisibleView = new TextView(this); | |
| invisibleView.setBackgroundColor(Color.TRANSPARENT); | |
| invisibleView.setHeight(150); | |
| lv.addHeaderView(invisibleView); | |
| ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.header,new String[] { "Apple", "Avocado", "Banana", | |
| "Blueberry", "Coconut", "Durian", "Guava", "Kiwifruit", | |
| "Jackfruit", "Mango", "Olive", "Pear", "Sugar-apple" }); | |
| lv.setAdapter(adapter); | |
| lv.setOnScrollListener(new OnScrollListener() { | |
| @Override | |
| public void onScrollStateChanged(AbsListView arg0, int arg1) { | |
| Log.i("onScrollStateChanged", arg1+""); | |
| scrollState = arg1; | |
| if(arg1==0){ | |
| }else{ | |
| invisibleView.setHeight(150); | |
| } | |
| } | |
| @Override | |
| public void onScroll(AbsListView arg0, int arg1, int arg2, int arg3) { | |
| Log.i("onScroll", arg1+" - "+arg2+" - "+arg3); | |
| } | |
| }); | |
| lv.setOnTouchListener(new OnTouchListener() { | |
| @Override | |
| public boolean onTouch(View arg0, MotionEvent arg1) { | |
| if(scrollState<2 && arg1.getAction()==MotionEvent.ACTION_MOVE){ | |
| invisibleView.setHeight(invisibleView.getHeight()+4); | |
| } | |
| if (arg1.getAction()==MotionEvent.ACTION_UP) { | |
| invisibleView.setHeight(500); | |
| } | |
| return false; | |
| } | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment