【问题标题】:Android - User Interface to Control Number InputAndroid - 控制数字输入的用户界面
【发布时间】:2014-07-30 20:21:05
【问题描述】:

我正在尝试制作一个漂亮的界面来控制我的应用程序中汽车数量的输入..

我想要汽车图标之类的东西,然后是一个上箭头和下箭头,这样用户就可以控制应用程序中汽车的数量。你明白了吗?

设计将是这样的图片:

但我不知道 Android 库是否已经可以处理这个问题。有什么问题吗?还是我需要自己制作小部件?

如果我需要自己做,最好的方法是什么?使用 3 个图像,并为箭头图像添加图像侦听器?我怎么会把它放在这样对齐的屏幕上?想象一下,我将拥有汽车和自行车......并且会在同一条线上?

提前非常感谢!

【问题讨论】:

  • 这取决于您希望它在您的应用中的显示方式。如果您希望在您显示的任何活动中使用它,只需将其添加到您用作活动视图的 XML 文件中。
  • 这并没有多大帮助,伙计 x)
  • 你可以使用Picker

标签: android input widget numbers controls


【解决方案1】:

假设您制作了 3 张单独的图像存储在您的可绘制文件夹中:upArrow.png、downArrow.png 和 car.png(或任何类型的图像,您可以选择)。要使它们像那样垂直对齐,您可以将它们放置在具有垂直方向的线性布局中。由于您希望箭头可点击,我会将它们制作为 ImageButtons 并将箭头图像用作按钮的背景。

<LinearLayout
    android:id="@+id/layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <ImageButton
        android:id="@+id/upButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/upArrow.png" 
        android:onClick="incrementCars" />

    <ImageView
        android:id="@+id/carImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/sample"
        android:contentDescription="This is a car" />

    <ImageButton
        android:id="@+id/downButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/downArrow.png" 
        android:onClick="decrementCars" />

</LinearLayout>

您可以对自行车做同样的事情,只需切换中心图像和 onClick 方法。

【讨论】:

  • 是的,我想这是唯一的方法。我无法适应 Picker 类?制作我的自定义课程?我会使用图像而不是 EditBox?这是可能的?非常感谢队友;)
猜你喜欢
  • 1970-01-01
  • 2022-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-08
  • 1970-01-01
相关资源
最近更新 更多