我目前正在小應用程序,在某些點用戶需要選擇一個選項。我收到的規格說明了水平列表和可供選擇的選項。該選項在箭頭指針下方選擇 - 就像在命運之輪中一樣。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>
也有解釋它的外觀圖片,如:
因此,當箭頭高於18cm時,則t他textview(價值)文本應該18釐米。
有人可以幫助我,或者至少說出我應該在Google中搜索什麼。
編輯:
有一件事我剛剛意識到我沒有提到 - 整個應用程序公頃s到是API 10+兼容。
HorizontalScrollView無法默認執行此操作。您可以自定義此視圖,或者您可以使用android庫視圖進行此操作,但是可以在運行時爲每個設備計算間距所需的項目居中。或使用可以爲此實現自定義視圖。 :) –