繁体   English   中英

如何减少 android 中的 material.switchmaterial.SwitchMaterial 端边距?

[英]How to reduce material.switchmaterial.SwitchMaterial end margin in android?

我在有一些空间的左边距中使用了“com.google.android.material.switchmaterial.SwitchMaterial” 如何减少呢?

我需要直接对齐每个人的文本。 我没有添加开关的结束边距或填充,我只设置了父布局边距。 在我的 XML 代码和 styles 下方。请提供您的建议以减少该保证金,谢谢。

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="10dp">

    <RelativeLayout
        android:id="@+id/who_can"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp">

        <com.google.android.material.textview.MaterialTextView
            style="@style/TextBlackRegular"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_toStartOf="@+id/video_view_result"
            android:singleLine="true"
            android:text="@string/who_can_view"
            android:textSize="@dimen/text_small"
            android:visibility="visible" />

        <com.google.android.material.textview.MaterialTextView
            android:id="@+id/video_view_result"
            style="@style/TextBlackRegular"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:singleLine="true"
            android:text="Everyone"
            android:textSize="@dimen/text_small" />

    </RelativeLayout>


    <com.google.android.material.switchmaterial.SwitchMaterial
        android:id="@+id/save_switch"
        style="@style/SwitchButtonStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/who_can"
        android:checked="true"
        android:text="@string/save_gallery"
        android:textSize="@dimen/text_small"
        app:trackTint="@color/colorSecondaryText" />
</RelativeLayout>


    <style name="SwitchButtonStyle" parent="Widget.MaterialComponents.CompoundButton.Switch">
            <item name="thumbTint">@drawable/switch_selector</item>
            <item name="android:fontFamily">@font/font_regular</item>
            <item name="android:textColor">@color/colorBlack</item>
        </style>

在此处输入图像描述

在您的relativeLayout/topRelativeLayout中,您添加了边距。 这意味着您想从各个方面获利。 这就是为什么它正在发生

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">

删除android:layout_margin="10dp" 添加margin_topmargin_right你想要做什么。

您应该为开关宽度提供换行内容,或者将其设置在新的相对布局中

如果您的结束边距在删除后显示

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">

然后

<com.google.android.material.switchmaterial.SwitchMaterial
        android:id="@+id/save_switch"
        style="@style/SwitchButtonStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/who_can"
        android:checked="true"
        android:text="@string/save_gallery"
        android:textSize="@dimen/text_small"
        app:trackTint="@color/colorSecondaryText" />

更改 SwitchButtonStyle 它会为您提供一些默认值,如果您共享整个文件,我们会很高兴

您可以看到主题中的默认可绘制对象(缩略图和轨道)具有此填充

在此处输入图像描述

所以方法是尝试使用您的自定义可绘制对象(但这可能会影响它们的外观)

        app:track="@drawable/track"
        android:thumb="@drawable/thumb"

暂无
暂无

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

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