Here is an example of my own head scrollable list view. It is a very simple and raw example. From this one, i think you can develop your own custom head scrollable list view as you wish. It just has a listview with several items and a sensor manager that retrieves the head angles. Based on the pitch angle and with the help of the linear mapping formula(mapped the head angle interval with the interval represented by the no. of items in the listview) I could easily make a head scrollable listview. I hope it helps.
Layout:
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.headangles.MainActivity" >
<ListView
android:id="@+id/list"
android:layout_height="wrap_content"
android:layout_width="match_parent">
</ListView>
</RelativeLayout>
Activity:
public class MainActivity extends Activity implements SensorEventListener {
private SensorManager mSensorManager;
private Sensor mOrientation;
ListView listView ;
ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
mOrientation = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
mSensorManager.registerListener(this, mOrientation, SensorManager.SENSOR_DELAY_GAME);
// Get ListView object from xml
listView = (ListView) findViewById(R.id.list);
// Defined Array values to show in ListView
String[] values = new String[] { "Android List View",
"Adapter implementation",
"Simple List View In Android",
"Create List View Android",
"Android Example",
"List View Source Code",
"List View Array Adapter",
"Android Example List View"
};
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, values);
// Assign adapter to ListView
listView.setAdapter(adapter);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
@Override
public void onSensorChanged(SensorEvent event) {
/* *** need only pitch angle (head bouncing backwards and forward)*** */
float pitch_angle = event.values[1];
/* *** first interval head angle degrees *** */
int top_head_angle_limit = -110;
int bot_head_angle_limit = -70;
/* *** second interval *** */
int top_list_item_limit = 0;
int bot_list_item_limit = adapter.getCount();
/* *** linear mapping/ map interval [-110,-70](head angle degrees) -> [0, 8] list items *** */
/* *** linear mapping formula: (val - A)*(b-a)/(B-A) + a *** */
if(pitch_angle >= top_head_angle_limit && pitch_angle <= bot_head_angle_limit){
int selection = (int) ((pitch_angle - top_head_angle_limit)*(bot_list_item_limit - top_list_item_limit)/(bot_head_angle_limit - top_head_angle_limit) + top_list_item_limit);
Log.e("selection: ", String.valueOf(selection));
listView.setSelection(selection);
}
}
}