React Native本机本地Picker内部项目未正确对齐

时间:2019-07-22 21:41:23

标签: react-native native-base

我正在尝试在右侧的CardItem中使用选择器。选取器在右侧正确显示,但其值与左侧对齐(下图)。为什么会发生?

enter image description here

<CardItem cardBody>
    <Left>
         <Entypo name="address" />
         <Text>State:</Text>
    </Left>
    <Right>
        <Item>
            <Picker
               mode="dropdown"
               iosHeader="Select State"
               placeholder="States"
               iosIcon={<Icon name="arrow-down" />}
               selectedValue={CurrentState}
               textStyle={{ color: '#C0C0C0' }}
               onValueChange={(text) => this.onChangeText(text, 'CurrentState')}
        >
            {Object.keys(localStates).map((key) => {
              return (
                  <Picker.Item
                     label={localStates[key]}
                     value={key}
                     key={key}
                   />
               );
             })}
           </Picker>
       </Item>
    </Right>
</CardItem>

localStates只是具有状态的键值const。

2 个答案:

答案 0 :(得分:0)

您可以尝试吗?

df1 <- structure(list(Item = c(1L, 1L), SubItem = c("1A", "1B"), Value = c("A", 
"B"), Count = 3:2), class = "data.frame", row.names = c(NA, -2L
))

df2 <- structure(list(Value = c("A", "B", "C", "D", "E", "F")), 
     class = "data.frame", row.names = c(NA, 
-6L))

答案 1 :(得分:0)

在处理RTL布局时,我遇到了类似的问题。将以下样式添加到res / values / styles.xml文件。这样可以在您的应用程序和苹果中对齐选择器项目,但在全球范围内希望这会有所启发

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- 
        ... existing styles
        --->
        <item name="android:spinnerItemStyle">@style/SpinnerItem</item>
        <item name="android:spinnerDropDownItemStyle">@style/SpinnerDropDownItem</item>
 </style>

然后在下面定义您的样式

<style name="SpinnerItem" parent="Theme.AppCompat.Light.NoActionBar">
   <item name="android:textAlignment">gravity</item>
   <item name="android:gravity">right</item>
</style>
<style name="SpinnerDropDownItem" parent="Theme.AppCompat.Light.NoActionBar">
   <item name="android:textAlignment">gravity</item>
   <item name="android:gravity">right</item>
   <item name="android:padding">10dp</item>
</style> 

如果要基于RTL布局(例如阿拉伯语)对齐,请使用以下代码

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- 
        ... existing styles
        --->
        <item name="android:spinnerItemStyle">@style/SpinnerItem</item>
        <item name="android:spinnerDropDownItemStyle">@style/SpinnerDropDownItem</item>
 </style>

然后在下面定义您的样式

<style name="SpinnerItem" parent="Theme.AppCompat.Light.NoActionBar">
   <item name="android:textAlignment">gravity</item>
   <item name="android:gravity">start</item>
</style>
<style name="SpinnerDropDownItem" parent="Theme.AppCompat.Light.NoActionBar">
   <item name="android:textAlignment">gravity</item>
   <item name="android:gravity">start</item>
   <item name="android:padding">10dp</item>
</style>