android - 如何减少android中的material.switchmaterial.SwitchMaterial结束边距?
问题描述
我在左边距使用了“com.google.android.material.switchmaterial.SwitchMaterial”,有一些空间。如何减少它?
我需要对齐每个人的文本。我没有添加开关的结束边距或填充,只有我设置的父布局边距。下面是我的 XML 代码和样式。请提供您的建议以减少该保证金,谢谢。
<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
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 它会为您提供一些默认值,如果您共享整个文件,我们会很高兴
推荐阅读
- image - Flutter/Dart 以相同格式重写图像
- svelte - Svelte 中未显示自定义 Google 登录按钮
- python - 错误:在python中找不到索引错误返回
- java - equiJoin 对象集合的有效方法
- python - AutoML Vision 元数据问题
- mysql - 字符编码问题 node.js mysql
- python - 我想在烧瓶中使用 shell 命令
- amazon-web-services - serverless create_domain - 无法创建自定义域
- javascript - 具有递归功能的轮播
- sql - 使用日期 startdatetime 和 end datetime 的 SQL 查询组