I was in the development of the time encountered such a demand, that is, in the ListView slide, need to the top of the column from transparent slowly to become opaque state, is the following effect
The first time to think very simple, nothing more than listening to the listview of the sliding distance, and then based on the distance to calculate the ratio of transparency, it can be, but in fact it is indeed done
It may be impossible to get direct access to the sliding distance of the ListView, and it needs to be dynamically computed.
The following posted all the code, do not want to code word, the recent cold, head dizzy, but also pain, the code more intuitive some
private void Initlistener () {Lvlist.setonscrollchangelistener (new View.onscrollchangelistener () {@Override public vo
ID Onscrollchange (View v, int scrollx, int scrolly, int oldscrollx, int oldscrolly) {}}); Lvlist.setonscrolllistener (New Abslistview.onscrolllistener () {@Override public void onscrollstatechanged ( Abslistview view, int scrollstate) {} @Override public void onscroll (Abslistview view, int firstvisibleitem, int visib Leitemcount, int totalitemcount) {//Logger.mylog ("firstvisibleitem=" + Firstvisibleitem + "visibleitemcount=" + Visible
ItemCount + "totalitemcount=" + totalitemcount);
Logger.mylog (Getscrooly () + "top=" + gettop ());
Tvtext.setalpha (Getalphafloat (Getscrooly ()));
}
});
/** * Get Gradient transparent value * @param dis * @return/public float getalphafloat (int dis) {int step = 5000;
if (dis = = 0) {return 0.0f;
if (Dis < step) {return (float) (DIS * (1.0/step));
}else{return 1.0f; }/** * Get up-sliding distance * @return distance/public int GetscrooLY () {View c = lvlist.getchildat (0);
if (null = = c) {return 0;
int firstvisibleposition = Lvlist.getfirstvisibleposition ();
int top = C.gettop (); /** * Declare that the top value here is always the distance of the first distance shown in the ListView entry, * and this representation in the coordinates is a negative number, so you need to take an absolute value for IT/return firstvisibleposition * C.G
Etheight () + math.abs (top);
/** * Get the height of the first distance * @return distance top/private int gettop () {View c = lvlist.getchildat (0);
if (null = = c) {return 0;
return C.gettop (); }
The above is a small set of Android to introduce the implementation of ListView sliding fade the top column instance code, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!