【问题标题】:TextView text and its drawable to the center of textviewTextView 文本及其可绘制到 textview 中心
【发布时间】:2020-05-19 22:02:16
【问题描述】:

我有一个带有drawableleft 的textview。由于 textview 覆盖了屏幕的整个宽度,所以我想要 textview 文本及其可绘制的左侧到 textview 的中心。目前只有文本与它的中心对齐,drawable 总是在它的最左边。所以请给我一些建议。

               <TextView
                android:layout_marginLeft="@dimen/_10sdp"
                android:layout_width="0dp"
                android:layout_height="@dimen/_40sdp"
                android:layout_weight="5"
                android:gravity="center"
                android:drawableLeft="@drawable/ic_cloud"
                android:paddingLeft="@dimen/_10sdp"
                android:text="@string/up"              
                />

【问题讨论】:

  • 可以添加整个布局代码吗?
  • 之所以叫drawableLeft是有原因的。

标签: android textview


【解决方案1】:

您无法使用drawableleft 实现此目的。将LayoutImageViewTextView 分开使用,如下所示:

<RelativeLayout 
  //add necessary attributes
  android:gravity="center_horizontal">

<ImageView
 //Add your image here
/>

<TextView
          android:layout_marginLeft="@dimen/_10sdp"
          android:layout_width="0dp"
          android:layout_height="@dimen/_40sdp"
          android:layout_weight="5"
          android:paddingLeft="@dimen/_10sdp"
          android:text="@string/up" />

</RelativeLayout/>

希望对你有帮助

【讨论】:

  • 我已经这样做了,但我正在寻找一种紧凑的方法来做到这一点。
猜你喜欢
  • 2014-06-23
  • 1970-01-01
  • 1970-01-01
  • 2013-10-22
  • 2013-01-14
  • 2013-10-13
  • 1970-01-01
  • 2020-03-17
  • 2013-04-01
相关资源
最近更新 更多