我试图以文本视图为中心来实现简单的初始化。
这是我的xml及其产生的图片:
<TextView
android:id="@+id/initial_view"
style="@style/my_style"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@color/black"
android:gravity="center"
android:textAllCaps="true"
android:text="C"
android:textColor="@color/font_white"
android:textSize="34sp" />
重力设定为中心。我也试过以编程方式设置引力。
我错过了什么或者这是一个机器人的错误吗?
风格是:
<style name="normal_text">
<item name="android:typeface">monospace</item>
</style>
答案 0 :(得分:0)
要让android:gravity="center"
工作,您的android:layout_width
和android:layout_height
需要设置为match_parent
或fill_parent
。