java - Android - 重量选择器
问题描述
我来自 iOS 和 Swift,我真的不知道如何简单地替换PickerView
.
在我的应用程序中,用户应该能够定义它的重量(例如 75.6 公斤)。
鉴于我是 Android 新手,我真的不知道如何重现它。我做了一些研究,它似乎是一个NumberPicker
?但我不知道如何拥有这两个不同的列。
解决方案
NumberPicker
通过使用并排放置的两个 s,您可以通过一些自定义来实现类似的效果:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<NumberPicker
android:id="@+id/first_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/CustomNumberPickerTheme" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="."
android:textSize="24sp" />
<NumberPicker
android:id="@+id/second_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/CustomNumberPickerTheme" />
</LinearLayout>
为了更好地匹配屏幕截图,aTextView
包含在两个NumberPicker
s 之间作为小数点以及CustomNumberPickerTheme
您需要在其中设置的自定义主题res/values/styles.xml
<resources>
...
<style name="CustomNumberPickerTheme" parent="AppTheme">
<item name="colorControlNormal">@android:color/transparent</item>
</style>
</resources>
推荐阅读
- r - R:显示 S3/S4 对象的内容
- php - 将数组插入另一个 PHP
- curl - 根据我的代码为 APEX 制作卷曲标注
- java - Hybris Smartedit 永远加载“我们正在准备要在 smartedit 上编辑的页面”
- git - 如何以非交互方式选择评论?
- random - 具有特定输出的随机发生器
- excel - 运行时错误“440”:发送多个电子邮件时对象不支持此方法
- javascript - 将数据推送到 Vue.js 数据属性,但新元素不会反应性地出现在 Google 地图上
- postgresql - 在一个脚本中从不同的表中多次删除
- unix - 使用 awk 计算组的主题实例