1

The footprints and clock app on a HTC sense phones use a slider control on the bottom buttonbar (see this movie for an example: https://docs.google.com/leaf?id=0B9hmEy_z2CRzOTJmYTVlNDktYjkwMS00YTM5LTk3ODQtYmIzODU4Yzk1YjA0&hl=en&authkey=CMWwwegG).

From the hierarchy viewer I can see that they use a custom control for this. I'm looking for a way to achieve the same effect. I want a buttonbar on the bottom of my app with a movable selector which I can drag from left to right and back, thereby selecting the different tabs.

Can anyone give some tips on how I might achieve this? Which layout controls could I use for this purpose? I know how to create the tabs and the button bar, but I'm a bit puzzled on the sliding selector.

Thanks and kind regards, Ivo

4

2 回答 2

1

要创建视图,您有两个主要选项。

一种是在 XML 中定义它,在您的 Activity 将使用的布局文件中。

<LinearLayout ... > <!-- or any other layout, see layout documentation in the SDK -->
  <ImageView ...    <!-- or another view as fits your needs -->
    android:id="@+id/myview"
    android:src="@drawable/myimage" ... />
</LinearLayout>

然后,您可以在调用 setContentView后使用 findViewById(R.id.myview)在代码中引用您的视图。(当然,如果你在 XML 文件中说“@+foo/bar”,你会使用 R.foo.bar)。

另一种方法是动态创建它并将其附加到视图层次结构中。

ImageView v = new ImageView();
v.setImageResource(R.drawable.myimage);
... // initialize your view here
parent.addChild(v);

...或者。

要获取事件,您还有多种选择。其中之一是继承 View(或 ImageView)并实现 onTouchEvent。您需要调整上面的代码以创建新类的实例而不是 ImageView(在 Java 代码中很明显,对于 XML,您将编写为标记名称并确保实现采用 (Context, AttributeSet) 的构造函数调用其超类的构造函数)。或者,您可以编写一个 TouchDelegate 并在您的 ImageView 上使用 setTouchDelegate,这在您的情况下可能更简单。

另一种方法是创建一个 GestureDetector 并使用它的 hitTest 方法将触摸与您的视图相匹配。对于您描述的任务,它是多余的,但是当您的应用程序变得更加复杂时,它可能会派上用场。

于 2010-10-13T12:46:11.937 回答
0

我会扩展 TabWidget 类来进行自己的渲染。您将受益于与其他选项卡系统和统一界面的热插拔,同时仍然能够以您想要的方式绘制您的选项卡栏。你会在 setCurrentTab 中开始你的动画。

于 2010-10-13T04:07:52.530 回答