-
-
Save rahulupadhyay/9739478 to your computer and use it in GitHub Desktop.
This file contains 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
import android.widget.ListView; | |
import android.widget.AbsListView; | |
import android.content.Context; | |
public class HalfCircleListView extends ListView implements AbsListView.OnScrollListener { | |
public HalfCircleListView(Context context) { | |
super(context); | |
setOnScrollListener(this); | |
} | |
@Override | |
public void onScrollStateChanged(AbsListView absListView, int i) { | |
//Ignored | |
} | |
@Override | |
public void onScroll(AbsListView absListView, int i, int i2, int i3) { | |
//Part of the magic happens here | |
absListView.invalidateViews(); | |
} | |
} |
This file contains 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
import android.content.Context; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.widget.ListView; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class MyActivity extends Activity | |
{ | |
/** Called when the activity is first created. */ | |
@Override | |
public void onCreate(Bundle savedInstanceState) | |
{ | |
super.onCreate(savedInstanceState); | |
ListView listView = new HalfCircleListView(this); | |
List<String> listOfStrings = new ArrayList<String>(); | |
for(int i = 0; i < 50 ; i++){ | |
listOfStrings.add("Value " + i); | |
} | |
listView.setAdapter(new ScrollAdapter(listOfStrings)); | |
setContentView(listView); | |
} | |
} |
This file contains 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
import android.widget.TextView; | |
import android.content.Context; | |
import android.graphics.Canvas; | |
import android.util.DisplayMetrics; | |
import android.content.res.Resources; | |
public class MyView extends TextView { | |
private static final int MAX_INDENT = 300; | |
private static final String TAG = MyView.class.getSimpleName(); | |
public MyView(Context context) { | |
super(context); | |
} | |
public void onDraw(Canvas canvas){ | |
canvas.save(); | |
float indent = getIndent(getY()); | |
//Part of the magic happens here too | |
canvas.translate(indent, 0); | |
super.onDraw(canvas); | |
canvas.restore(); | |
} | |
public float getIndent(float distance){ | |
float x_vertex = MAX_INDENT; | |
DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics(); | |
float y_vertex = displayMetrics.heightPixels / 2 / displayMetrics.density; | |
double a = ( 0 - x_vertex ) / ( Math.pow(( 0 - y_vertex), 2) ) ; | |
float indent = (float) (a * Math.pow((distance - y_vertex), 2) + x_vertex); | |
return indent; | |
} | |
} |
This file contains 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
import java.util.List; | |
import android.widget.BaseAdapter; | |
import android.view.ViewGroup; | |
import android.view.View; | |
import android.util.Log; | |
public class ScrollAdapter extends BaseAdapter { | |
private List<String> scrollViews; | |
private static final String TAG = ScrollAdapter.class.getSimpleName(); | |
public ScrollAdapter(List<String> scrollViews){ | |
this.scrollViews = scrollViews; | |
} | |
@Override | |
public int getCount() { | |
return scrollViews.size(); | |
} | |
@Override | |
public String getItem(int i) { | |
return scrollViews.get(i); | |
} | |
@Override | |
public long getItemId(int i) { | |
return i; | |
} | |
@Override | |
public View getView(int i, View view, ViewGroup viewGroup) { | |
if(view == null){ | |
view = new MyView(viewGroup.getContext()); | |
} | |
MyView currentView = (MyView) view; | |
String itemViewType = getItem(i); | |
Log.d(TAG, itemViewType); | |
((MyView) view).setText(itemViewType); | |
return currentView; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment