【问题标题】:Separate padding values for checkbox and text inside CheckedTextViewCheckedTextView 中复选框和文本的单独填充值
【发布时间】:2018-02-14 23:03:29
【问题描述】:

我正在尝试根据最新的材料设计指南使用 CheckedTextView 小部件构建我的多项选择布局。但我找不到分别为复选框和文本视图设置左填充的方法(图标为 16dp,文本为 72)。 我能找到的最可接受的解决方案是使用 android:drawablePadding 属性,但我认为它不太正确。 是否可以在 CheckedTextView 中单独设置填充值?

<?xml version="1.0" encoding="utf-8"?>

    <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"

        android:id="@android:id/text1"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:gravity="center_vertical"
        android:textSize="16sp"
        android:textColor="#000000"
        android:paddingLeft="16dp"
        android:drawableLeft="?android:attr/listChoiceIndicatorMultiple"
        android:drawablePadding="36dp"/>

【问题讨论】:

  • 请发布一些代码,如果您发布代码,我可能会提供帮助。
  • 这是我的 Custom_Multiple_Selection.xml
  • 就个人而言,我会以编程方式处理此问题。找到 CheckedTextView 的来源并根据您的需要进行修改。如果您不想弄乱其他人编写的代码,请创建自己的小部件。毕竟这是一个textView 和一个复选框...
  • 您是否尝试过定义一个自定义的可绘制对象(最有可能是 layeredlistdrawable),它包含默认的 android 清单?这样你就可以控制每边有多少填充

标签: android android-layout checkedtextview


【解决方案1】:

试试这个,它对我有用,添加一个“填充”属性:

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:background="@color/grey"
android:textColor="@color/white"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:ellipsize="marquee"/>

【讨论】:

    【解决方案2】:
    Try this one: (This is under RelativeLayout)
    
    <CheckedTextView
        android:id="@+id/checkedTextView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:paddingStart="16dp"
        android:paddingEnd="16dp"
        android:text="@string/text"
        android:checkMark="?android:attr/textCheckMark"
        android:checked="false" />
    
    It will stay like this:
    
    Layout:
       |                                  |
       | Text for checkedTextView:      V |
       |                                  | 
    

    【讨论】:

      【解决方案3】:

      我迟到了,但以防万一有人在寻找解决方案,以下是我使用 CheckBox 小部件的方法:

          <CheckBox
              android:id="@+id/textView"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="TextView"
              android:minHeight="30dp"
              android:textColor="#ffffff"
              android:layout_centerVertical="true"
      
              android:layout_marginStart="16dp"
              android:paddingStart="56dp"/>
      

      android:layout_marginStart="16dp" 设置图标和文本的边距,而 android:paddingStart="56dp" 设置文本和图标之间的填充。

      【讨论】:

      • 关于CheckedTextView的问题。不是Checkbox
      猜你喜欢
      • 2022-01-02
      • 1970-01-01
      • 2017-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-28
      • 1970-01-01
      • 2014-11-08
      相关资源
      最近更新 更多