Jim*_*Jim 5 react-native react-native-android
创建了一个列表组件,它有一个图像、一些文本和一个按钮。图像上有边框半径和边框颜色。
问题:android 上的彩色边框半径未被识别,但在 iOS 上它工作正常......
这是代码:
列表:
import React, { useState } from 'react';
import {
View,
Text,
Image,
StyleSheet,
Modal,
FlatList,
Dimensions,
TouchableOpacity,
TouchableWithoutFeedback
} from 'react-native';
import { Svg, Path, G, Line } from 'react-native-svg';
const { width } = Dimensions.get('window');
const BlockList = (props) => {
const onPress = (name) => {
alert('Unblocking ' + name);
};
return (
<FlatList
style={styles.container}
data={props.data}
renderItem={({ item, index }) => (
<View style={styles.itemContainer}>
<View style={styles.leftSide}>
<Image source={item.img} style={styles.img} resizeMode={'contain'} />
<Text style={{ fontSize: 18, fontWeight: 'bold', color: '#454A66' }}>{item.name}</Text>
</View>
<View style={styles.rightSide}>
<TouchableOpacity onPress={() => onPress(item.name)} style={styles.btn}>
<Text style={{ fontWeight: 'bold', color: '#fff' }}>Unblock</Text>
</TouchableOpacity>
</View>
</View>
)}
/>
);
};
const styles = StyleSheet.create({
itemContainer: {
flexDirection: 'row',
width: width * 0.95,
backgroundColor: '#fff',
marginHorizontal: width * 0.025,
marginBottom: width * 0.02,
borderRadius: 18,
justifyContent: 'space-between',
alignItems: 'center',
paddingVertical: width * 0.02,
shadowColor: '#333',
shadowOffset: {
width: 3,
height: 3
},
shadowOpacity: 0.5,
shadowRadius: 3,
elevation: 5
},
img: {
borderRadius: 50,
borderWidth: 2,
borderColor: '#219F75',
height: width * 0.125,
width: width * 0.125,
marginHorizontal: width * 0.05
},
btn: {
borderRadius: 11,
backgroundColor: '#219F75',
padding: width * 0.0275
},
leftSide: {
flexDirection: 'row',
alignItems: 'center'
},
rightSide: {
marginRight: width * 0.05
}
});
export default BlockList;
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况以及如何获得我的边界半径?
如果我们想要视图圆,我们也可以通过设置borderRadius等于视图高度(宽度)的一半来实现。
<View
style={{
borderWidth:1,
borderColor:'rgba(0,0,0,0.2)',
alignItems:'center',
justifyContent:'center',
width:100,
height:100,
backgroundColor:'#fff',
borderRadius:50,
}}
/>
Run Code Online (Sandbox Code Playgroud)
在您的情况下,您的图像设置resizeMode。所以没有显示出你想要的效果。为此尝试在视图或使用中移动它resizeMode:stretch;resizeMode:cover或将其删除。
<View style={styles.leftSide}>
<Image source={item.img} style={styles.img}/>
<Text style={{ fontSize: 18, fontWeight: 'bold', color: '#454A66' }}>{item.name}</Text>
</View>
img: {
borderRadius: width * 0.125*0.5,
borderWidth: 2,
borderColor: '#219F75',
height: width * 0.125,
width: width * 0.125,
marginHorizontal: width * 0.05
},
Run Code Online (Sandbox Code Playgroud)
contains:均匀缩放图像(保持图像的长宽比),使图像的两个尺寸(宽度和高度)等于或小于视图的相应尺寸(减去填充)。
| 归档时间: |
|
| 查看次数: |
2864 次 |
| 最近记录: |