Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

kivy - how can i create a KivyMD card with adjustable height

I am trying to make a kivymd card which has an adjustable height but is not able to. I would like the card to adjust its height according to the items called in it. also, all the items called in it to feet in. am not sure if it's ok to use a card or just a boxlayout in this type of application

from kivy.uix.screenmanager import Screen
from kivymd.app import MDApp
#from kivymd.uix.button import MDCard
from kivymd.uix.card import MDCard,MDSeparator
from kivymd.uix.label import MDLabel
from kivymd.uix.list import TwoLineAvatarListItem,ImageLeftWidget
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder


KV = '''

<Post_message>: 

    MDBoxLayout:
        orientation: "vertical"
        id: box_bottom
        adaptive_height: True
        padding: "20dp", "5dp", 0, 0
        size_hint_y: None
        spacing: "1dp"

        MDLabel:
            text:"Midrange and flagship."
            size_hint_y: None
            height: self.texture_size[1]
            pos_hint: {"center_y": .5}
            theme_text_color: "Primary"

<Post_profile>:

    MDBoxLayout:
        adaptive_height: True
        padding:"-17dp", 0, 0, 0

        TwoLineIconListItem:
            text:f"[color=#00ACC1]Profile name[/color]"
            markup: True 
            secondary_text: "Location"
            height: dp(48)
            divider: None
            _txt_bot_pad: dp(5)
            IconLeftWidget:
                icon:'kivymd_logo.png'    
                
                
<Post_bottom_bar>:
    orientation: "horizontal"
    adaptive_height: True

    MDBoxLayout:
        orientation: "horizontal"
        adaptive_height: True
        padding: "25dp", 0, 0, "15dp"

        MDLabel:
            text:f"[color=#00ACC1]2.jun.2020[/color]"
            markup: True 
            size_hint_y: None
            height: self.texture_size[1]
            pos_hint: {"center_y": .5}

    MDBoxLayout:
        orientation: "horizontal"
        adaptive_height: True
        padding: "30dp", 0, 0, 0
        MDIconButton:
            icon: "heart-outline"
            on_release:
                #self.grow()
                self.icon = "heart" if self.icon == "heart-outline" else "heart-outline"
        MDIconButton:
            icon: "message"
            on_release:
                #self.grow()
        MDIconButton:
            icon: "dots-vertical"
            on_release:
                #self.grow()

'''
class Post_bottom_bar(BoxLayout):
    pass


class Post_profile(BoxLayout):
    pass


class Post_message(BoxLayout):
    pass



class MainApp(MDApp):
    def build(self):
        self.theme_cls.theme_style="Dark"
        Builder.load_string(KV)
        screen = Screen()
        
        post_card = MDCard(
            
            padding = [0, 0, 0, 0],
            spacing = "5dp",
            border_radius = 20,
            radius = [15, 15, 15, 15],
            orientation= "vertical",
            size_hint= [1, None],     
            elevation=9,
            )
        

        
        post_card.add_widget(Post_profile()) 
        
        post_card.add_widget(Post_message()) 
              
        
        post_card.add_widget(Post_bottom_bar())       
        
        screen.add_widget(post_card)
        
        return screen
        
MainApp().run()

am additional corrections and suggestions are welcomed

question from:https://stackoverflow.com/questions/65869559/how-can-i-create-a-kivymd-card-with-adjustable-height

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...