1

I am currently working on small app, where at some point user need to choose one option. The specification which I've received says about horizontal list with options to choose from. The option is chosen when it is below an arrow pointer - something like in wheel of fortune.

This is what I've done so far:

My activity

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        LinearLayout tl = (LinearLayout) findViewById(R.id.index);
        for (int i = 0; i < 10; i++) {
            TextView textview = new TextView(this);
            textview.setLayoutParams(new LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            textview.setText("Text " + i);
            tl.addView(textview);
        }
    }
}

My 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" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello_world" />
        ... the rest of normal layout
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/value" />

        <HorizontalScrollView
            android:id="@+id/horizontalScrollView"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:scrollbars="none" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:id="@+id/index"
                android:orientation="horizontal" >
                ... there i put all the elements
            </LinearLayout>
        </HorizontalScrollView>
    </LinearLayout>

</RelativeLayout>

Also there is a picture explaining how it looks like: Sample

So, when the arrow is above 18cm, then the textview (value) text should be 18cm.

Can someone help me with that, or at least say what should I search for in Google.

EDIT:

There is one thing I've just realised I didn't mention about - the whole app ha s to be API 10+ compatible.

sebap123
  • 2,541
  • 6
  • 45
  • 81
  • HorizontalScrollView is not able to do this by default. you have customise this view or you can use android gallery view for this but to center the items you need to calculate the spacing for each device at run time. or use can implement a custom view for this. :) – Ali Imran Oct 28 '13 at 06:42

2 Answers2

6

The widget you are looking for is similar to the android horizontal wheel. There is an implementation at android-spinnerwheel which can be what you need.

enter image description here

TheFlash
  • 5,997
  • 4
  • 41
  • 46
Amulya Khare
  • 7,718
  • 2
  • 23
  • 38
1

This might not be that helpful. But this should help you to get started with.

There is a class called Gallery in Android which can be used for this kind of implementation. It has center lock for the child elements with horizontal scrolling. But this got deprecated in Android API 16.

Gallery Deprecated. So using this is not recommended.

That being said, there are few open source projects that helps you achieve this implementation of yours. One such solution is this, https://stackoverflow.com/a/12240387/603744. You can start here and make your way through I guess.

Community
  • 1
  • 1
Andro Selva
  • 53,910
  • 52
  • 193
  • 240