簡體   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