2013-10-28 92 views
1

我目前正在小應用程序,在某些點用戶需要選擇一個選項。我收到的規格說明了水平列表和可供選擇的選項。該選項在箭頭指針下方選擇 - 就像在命運之輪中一樣。Android水平清單輪狀旋轉

這是我迄今所做的:

我的活動

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); 
     } 
    } 
} 

我的佈局:

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

也有解釋它的外觀圖片,如: Sample

因此,當箭頭高於18cm時,則t他textview(價值)文本應該18釐米。

有人可以幫助我,或者至少說出我應該在Google中搜索什麼。

編輯:

有一件事我剛剛意識到我沒有提到 - 整個應用程序公頃s到是API 10+兼容。

+0

Horizo​​ntalScrollView無法默認執行此操作。您可以自定義此視圖,或者您可以使用android庫視圖進行此操作,但是可以在運行時爲每個設備計算間距所需的項目居中。或使用可以爲此實現自定義視圖。 :) –

回答

1

這可能沒有那麼大的幫助。但這應該可以幫助你開始。

在Android中有一個名爲Gallery的類,可以用於這種實現。它具有水平滾動的子元素的中心鎖定。但是這在Android API 16中已棄用。

Gallery Deprecated。所以不建議使用這個。

這就是說,有幾個開源項目可以幫助你實現你的這個實現。一個這樣的解決方案是這樣的,https://stackoverflow.com/a/12240387/603744。我想你可以從這裏開始並通過你的方式。

6

您正在尋找的小工具類似於android水平輪。有一個實現在android-spinnerwheel這可能是你需要的。

enter image description here