简体   繁体   English

按钮宽度在 pc 上是对称的,但在 android python/kivy 上不是对称的

[英]Button width is symmetrical on pc but not symmetrical on android python/kivy

I created a custom Toggle Button, setting size_hint_x to None to put width .我创建了一个自定义切换按钮,将size_hint_x设置为None以放置width The button is perfect on pc but on android it is as if the width of the button had been reset.该按钮在 pc 上是完美的,但在 android 上就好像按钮的宽度已被重置。

MyWidget.kv: MyWidget.kv:

#:import Window kivy.core.window.Window

<MyButton>:
    size_hint_x: None
    width: Window.width/3
    font_name: "path/to/font.ttf"
    md_bg_color: app.theme_cls.bg_dark
    background_down: get_color_from_hex("#2e5871")
    font_color_normal: app.theme_cls.primary_color
    font_color_down: app.theme_cls.primary_light
    allow_no_selection: False

MyWidget.py我的小部件.py

from kivymd.uix.behaviors.toggle_behavior import MDToggleButton
from kivymd.uix.button import MDRectangleFlatButton

class MyButton(MDRectangleFlatButton, MDToggleButton):
    def __init__(self, **kwargs):
        self.background_normal = 1, 1, 1, 1
        super().__init__(**kwargs)

Location I'm using the button:我使用按钮的位置:

MDRelativeLayout:
    size_hint: 1, None
    height: dp(45)

    MyButton:
        text: "List 1"
        group: "list"
        pos_hint: {"top":1, "left":1}

    MyButton:
        text: "List 2"
        group: "list"
        pos_hint: {"top":1, "center_x":.5}

    MyButton:
        text: "List 3"
        group: "list"
        pos_hint: {"top":1, "right":1}

Here is the app images这是应用程序图像

Application on PC电脑应用

Application on Android安卓应用

The issue was resolved by changing the size_hint_x instead of the width .该问题已通过更改size_hint_x而不是width得到解决。

Obrigado @ApuCoder奥布里加多@ApuCoder

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM