java - Android - 重量选择器

标签 java android uipickerview picker numberpicker

我来自 iOS 和 Swift,我真的不知道如何才能简单地替换 PickerView

在我的应用中,用户应该能够定义它的重量(例如 75.6 千克)。

最好的方法似乎是这样的: enter image description here

鉴于我是 Android 的新手,我真的不知道如何重现它。我做了一些研究,它似乎是一个 NumberPicker?但我不知道如何拥有这两个不同的列。

最佳答案

enter image description here

通过使用并排放置的两个 NumberPicker,您可以通过一些自定义实现类似的效果:

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

为了更好地匹配屏幕截图,在两个 NumberPicker 之间包含了一个 TextView 作为小数点以及一个自定义主题 CustomNumberPickerTheme你需要在 res/values/styles.xml

中设置
<resources>

    ...

    <style name="CustomNumberPickerTheme" parent="AppTheme">
        <item name="colorControlNormal">@android:color/transparent</item>
    </style>
</resources>

关于java - Android - 重量选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51528287/

相关文章:

java - ListView "onPopulate"监听器?

java - 如何获取tomcat服务器中所有已部署的应用程序

Java:字节未正确传输

android - 使用 Dagger 2 的 CustomView 依赖注入(inject)(在 Activity 范围内)

ios - iPhone开发: How to transfer information from one . m文件到另一个

java - Spring 重试: NeverRetryLogic Not working as I expected with ExceptionClassifierRetryPolicy

java - 当按钮的setOnClickListener第二次执行时

android - Firebase 通知 : activity doesn't launch when status bar notification is clicked

swift - 为什么我的 UIPickerview 无法在 UIAlertcontroller 中工作?

ios - 如何从具有多个组件的 pickView 中获取确切的值