首页 > 解决方案 > TextView 文本及其可绘制到 textview 中心

问题描述

我有一个带有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"              
                />

标签: androidtextview

解决方案


您无法使用drawableleft. 与和分开Layout使用ImageViewTextView如下所示:

<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/>

希望这可以帮助


推荐阅读