Android:文本不在textView中居中?
问题描述:
编辑:对不起,这是我的实施中的一个问题,布局权重不加1,因此问题。它在我修复layoutWeight之后起作用。Android:文本不在textView中居中?
我不知道为什么,但我无法在此custom TextView里面居中文字,请有人请帮忙。我尝试了各种各样的东西,但都没有工作。 IconTextView内的图标更靠近右侧,而不是中心。谢谢 !!
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25">
<com.malinskiy.materialicons.widget.IconTextView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ripple_effect"
android:gravity="center"
android:text="{zmdi-play}"
android:textColor="#ffffff"
android:textSize="40dp"
app:hacky_preview="true" />
</LinearLayout>
答
尝试
android:textAlignment="gravity"
添加到您的IconTextView
元素
答
这不是一个妥善的解决办法,但是,因为也许问题是在IconTextView的实现,你可以尝试设置IconTextView与wrap_content
并将整个IconTextView集中在包装LinearLayout中。事情是这样的:
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center">
<com.malinskiy.materialicons.widget.IconTextView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/ripple_effect"
android:text="{zmdi-play}"
android:textColor="#ffffff"
android:textSize="40dp"
app:hacky_preview="true" />
</LinearLayout>
答
可以使用文本视图相对相对布局如下面的代码
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.malinskiy.materialicons.widget.IconTextView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/ripple_effect"
android:text="{zmdi-play}"
android:textColor="#ffffff"
android:textSize="40dp"
app:hacky_preview="true" />
</RelativeLayout>
希望这将帮助你
答
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.malinskiy.materialicons.widget.IconTextView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ripple_effect"
android:gravity="center"
android:text="{zmdi-play}"
android:textColor="#ffffff"
android:textSize="40dp"
app:hacky_preview="true" />
</LinearLayout>
试试这个..可以帮助你..
+0
谢谢,请参阅编辑。 – varunkr
分享屏幕截图。 –