AndroidのTextView之CompoundDrawable那些坑

    TextView有几个属性android:drawableXXX,通常是在环绕文字周边显示一个图像,但是这有个坑就是文字和图片可能会对不齐。

纵使你设置gravity还是layout_gravity=center都没有任何效果。

  一般在app的底部导航栏,会用RadioButton去实现。RadioGroup应该是一个线性布局,支持oratation属性可以横的也可以竖得排列。

既然是底部导航栏,一般都会设置横向布局,然后每一个RadioButton把weight属性同时设为1,layout_width设为match_parent,然后再

把button属性设置@null,甚至把背景属性设置为空的或者透明的,还是没有效果的。

  

  上图的代码:

  

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableTop="?android:attr/listChoiceIndicatorSingle"
            android:text="@string/hello_world" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:drawableTop="?android:attr/listChoiceIndicatorSingle"
            android:text="@string/hello_world" />

        <TextView
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:drawableTop="?android:attr/listChoiceIndicatorSingle"
            android:text="@string/hello_world" />
    </LinearLayout>

 

  看到上面的截图和代码,只有宽度设置为wrap_content才能居中。再试着把gravity设置为center,结果你到会大吃一惊。

  

  设置居中文字还在与图标的中间左对齐,太坑了。

  我信心满满的把属性都去掉,然后一不小心又没对齐了?

  

  如果是一个字用wrap竟然也没用,加上gravity这个我字就偏右一点,不加就偏左一点。

  如果用线性布局去装一个ImageView和TextView编译器还提示你用TextView的drawablexx去实现。。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值