java 如何更改数字选择器 Android 的大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28256651/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 13:16:43  来源:igfitidea点击:

How to change size of a numberpicker Android

javaandroidsizenumberpicker

提问by Jefferson

I'm trying to decrease the size of an Android numberpicker, but already tried several things and I could not. I did not find a responsible attribute the change in size. Wanted to do the following:

我正在尝试减小 Android numberpicker 的大小,但已经尝试了几件事,但我做不到。我没有找到一个负责任的属性改变大小。想做以下事情:

enter image description here

在此处输入图片说明

Must decrease because I have to put the numberpicker on a screen with lots of information. Any help will be appreciated.

必须减少,因为我必须将数字选择器放在包含大量信息的屏幕上。任何帮助将不胜感激。

回答by Shah

I was facing a similar problem, I wanted to increase the text size of the NumberPicker but couldn't find a way to do it as part of the Widget. In my research I found the following solution:

我遇到了类似的问题,我想增加 NumberPicker 的文本大小,但找不到将其作为 Widget 的一部分的方法。在我的研究中,我找到了以下解决方案:

<NumberPicker
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleX="0.75"
    android:scaleY="0.75"/>

Think of scaleX and scaleY as a magnifying factor. Values < 1 will shrink the Widget, 1 will have no change, and > 1 will increase its size.

将 scaleX 和 scaleY 视为放大系数。值 < 1 将缩小 Widget,1 将没有变化,> 1 将增加其大小。

回答by Luis Felipe de Melo

You may change directly on XML properties.

您可以直接更改 XML 属性。

<NumberPicker
         android:id="@+id/numberPicker"
         android:layout_width="wrap_content"
         android:layout_height="90dp"
          android:orientation="vertical" />

回答by Vinayak

Number Picker is quite not straight forword to modify or customize. Below is code which will adjust the NumberPicker height to 360dp actual values are considered match parent or wrap content in height will not be considered.

Number Picker 并不是直接修改或自定义的。下面是将 NumberPicker 高度调整为 360dp 的代码,实际值被认为是匹配父级或高度的包裹内容将不被考虑。

Text color,Text size,divider color can be changed as per style mentioned below

文字颜色、文字大小、分隔线颜色可以按照下面提到的样式进行更改

Height and style of number picker:

数字选择器的高度和样式:

<NumberPicker
  android:id="@+id/np_month"
  android:layout_width="wrap_content"
  android:layout_height="360dp"
  android:theme="@style/AppTheme.Picker" />

Style:

风格:

  <style name="AppTheme.Picker" parent="Theme.AppCompat.Light.NoActionBar" >
        <item name="android:textColorPrimary">@android:color/white</item>
        <item name="android:textSize">40sp</item>
        <item name="colorControlNormal">@android:color/transparent</item>
    </style>