React原生UI挑战

zqdjd7g9  于 2023-01-27  发布在  React
关注(0)|答案(1)|浏览(106)

今天我试着做了一个如下所示的设计!

但最后,我成功地做到了50%。不能把最右边的按钮放在View的末尾。所以到目前为止,我的代码-

const data = [
    {
        title: "Introduction\n06:25/17:45",
    },
    {
        title: "What is Design Thinking\n00:00 / 12:50",
    },
    {
        title: "What is UX Design?\n00:00/09:32",
    },
];
...
const buttonStyle = {
    flex: 1,
    alignItems: "center",
    marginLeft: 15,
    marginRight: 15,
    flexDirection: "row",
    height: 57,
    borderRadius: 10,
    backgroundColor: "#fff",
    marginTop: "5%",
    shadowColor: "#000",
    shadowOffset: {
        width: 0,
        height: 6,
    },
    shadowOpacity: 0.39,
    shadowRadius: 8.3,

    elevation: 13,
};

<ScrollView
  style={{
      flex: 1,
      width: "100%",
      paddingTop: 20,
  }}
>
    {data.map((item, index) => {
        return (
          <View style={buttonStyle} key={index}>
              <Image
                source={require("./assets/play.png")}
                style={{ height: 32, width: 32, marginLeft: "5%" }}
              />
              <Text
                style={{
                    color: "#b5b3c2",
                    marginLeft: 15,
                    textAlign: "left",
                }}
              >
                  {item.title}
              </Text>
              <Image
                source={require("./assets/fail.png")}
                style={{
                    height: 32,
                    width: 32,
                    justifyContent: "flex-end",
                }}
              />
          </View>
        );
    })}
</ScrollView>

正如你所看到的,最右边的图片是不是在正确的位置?我不知道如何解决它?对不起,我的英语不好!也页隐藏我的一部分,我的ScrollView

oug3syen

oug3syen1#

justifyContent类似于标准Flexbox中的justify-content。它用于对齐容器中的元素。应使用alignSelf: 'flex-end',或在<Image />组件的左侧设置自动边距:

<Image
   source={require("./assets/fail.png")}
   style={{
        height: 32,
        width: 32,
        justifyContent: "flex-end",
    }}
/>

关于缺少的下拉阴影,您需要使用contentContainerStyle属性向ScrollView的内部组件添加填充:

<ScrollView
    style={{ flex: 1, width: "100%", paddingTop: 20 }}
    contentContainerStyle={{ paddingBottom: 20 }}
>

还值得注意的是,这可能应该呈现为<FlatList />,而不是<ScrollView />

相关问题