【问题标题】:How do I add padding/margin to the left side of the selected menu option in TextInputLayout?如何将填充/边距添加到 TextInputLayout 中所选菜单选项的左侧?
【发布时间】:2021-05-29 23:28:10
【问题描述】:

I have the following exposed dropdown menu that looks like this when an option is selected:

这是我的 XML 布局中公开的下拉菜单的内容:

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/drop_down_menu"
    style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_marginEnd="8dp"
    android:theme="@style/Theme.MaterialComponents.Light.NoActionBar"
    app:layout_constraintBottom_toBottomOf="@+id/text_view_1"
    app:layout_constraintEnd_toStartOf="@+id/text_view_2"
    app:layout_constraintTop_toTopOf="@+id/text_view_3">

    <com.google.android.material.textfield.MaterialAutoCompleteTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="none" />

</com.google.android.material.textfield.TextInputLayout>

如何在所选选项的左侧添加空格?

【问题讨论】:

  • android:paddingStart on MaterialAutoCompleteTextView 应该工作不是吗?
  • 是的,我添加了它并且它有效。谢谢!

标签: android material-components-android android-textinputlayout


【解决方案1】:

感谢 Zain 已经为您的查询提供了帮助,我很乐意在上面添加一些樱桃,以便您以后在添加与空间相关的查询时轻松决定在你的脑海中。

当我们想在两个视图之间留出空间时,我们会想到两个选项paddingma​​rgin

填充用于在视图及其内容之间添加空白。

边距用于在两个不同的视图之间添加空格。

对于内边距和边距,我们有两种方法来设置它们,

  • 将所有边设置为相等值
  • 根据要求设置侧面特定值

具有相等值的所有边:

您可以使用android:padding="10dp" 设置边距为 10dp,android:layout_margin="10dp" 设置边距为 10dp

具有特定值的边:

填充

  • android:paddingBottom 设置底部边缘的填充
  • android:paddingStart 设置起始边缘的填充意味着在视图的左侧
  • android:paddingEnd 将边距设置在视图的右侧
  • android:paddingTop 设置顶部边缘的填充

保证金

  • android:layout_marginBottom 指定此视图底部的额外空间。
  • android:layout_marginEnd 指定端侧的额外空间,表示此视图的右侧。
  • android:layout_marginStart 指定起始侧的额外空间,表示此视图的左侧。
  • android:layout_marginTop 指定此视图顶部的额外空间。

【讨论】:

    猜你喜欢
    • 2014-09-11
    • 2011-08-06
    • 1970-01-01
    • 2015-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-19
    • 1970-01-01
    相关资源
    最近更新 更多