KivyMD 卡内图像的圆角
Rounding corners of image inside KivyMD Card
我想在图像上添加海拔效果。所以我基本上将它添加到 MDCard 中。现在图像看起来不错,但我想使图像的角变圆。因此,我尝试将 MDCard 的边角做成圆角,但是当完全拉伸时,图像只是从盒子里伸出来。
看起来像这样:
但我希望它有像这样的圆角但图像完全拉伸
但是当我拉伸图像时,图像的角覆盖了MDCard的圆角
这是我正在使用的代码部分:
song_image = AsyncImage(source=self.image_url, pos_hint={"center_x":0.5, "center_y":0.5}, allow_stretch=True)
card = MDCard(orientation='vertical', border_radius= 20, radius= [15], pos_hint={"center_x":0.5, "center_y":0.65}, size_hint=(None, None), size=(Window.size[0]*0.9, Window.size[0]*0.9))
card.add_widget(song_image)
self.details_screen.add_widget(card)
知道怎么做吗?或任何其他方式在不使用 kivyMD 卡的情况下制作带有高度的圆角
from kivy.uix.modalview import ModalView
from kivy.lang import Builder
from kivymd import images_path
from kivymd.app import MDApp
from kivymd.uix.card import MDCard
Builder.load_string(
'''
<Card>:
elevation: 10
radius: [36, ]
FitImage:
id: bg_image
source: "images/bg.png"
size_hint_y: .35
pos_hint: {"top": 1}
radius: [36, 36, 0, 0, ]
''')
class Card(MDCard):
pass
class Example(MDApp):
def build(self):
modal = ModalView(
size_hint=(0.4, 0.8),
background=f"{images_path}/transparent.png",
overlay_color=(0, 0, 0, 0),
)
modal.add_widget(Card())
modal.open()
Example().run()
我想在图像上添加海拔效果。所以我基本上将它添加到 MDCard 中。现在图像看起来不错,但我想使图像的角变圆。因此,我尝试将 MDCard 的边角做成圆角,但是当完全拉伸时,图像只是从盒子里伸出来。
看起来像这样:
但我希望它有像这样的圆角但图像完全拉伸
但是当我拉伸图像时,图像的角覆盖了MDCard的圆角 这是我正在使用的代码部分:
song_image = AsyncImage(source=self.image_url, pos_hint={"center_x":0.5, "center_y":0.5}, allow_stretch=True)
card = MDCard(orientation='vertical', border_radius= 20, radius= [15], pos_hint={"center_x":0.5, "center_y":0.65}, size_hint=(None, None), size=(Window.size[0]*0.9, Window.size[0]*0.9))
card.add_widget(song_image)
self.details_screen.add_widget(card)
知道怎么做吗?或任何其他方式在不使用 kivyMD 卡的情况下制作带有高度的圆角
from kivy.uix.modalview import ModalView
from kivy.lang import Builder
from kivymd import images_path
from kivymd.app import MDApp
from kivymd.uix.card import MDCard
Builder.load_string(
'''
<Card>:
elevation: 10
radius: [36, ]
FitImage:
id: bg_image
source: "images/bg.png"
size_hint_y: .35
pos_hint: {"top": 1}
radius: [36, 36, 0, 0, ]
''')
class Card(MDCard):
pass
class Example(MDApp):
def build(self):
modal = ModalView(
size_hint=(0.4, 0.8),
background=f"{images_path}/transparent.png",
overlay_color=(0, 0, 0, 0),
)
modal.add_widget(Card())
modal.open()
Example().run()