【发布时间】:2016-07-28 06:00:16
【问题描述】:
在我的相对布局中,我有一个圆形视图和一个 TextView。我想将 TextView 完全集中在圆形视图中。我怎么做?我到目前为止的代码如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<View
android:id="@+id/firstCircle"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="24dp"
android:background="@drawable/circle" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="@+id/number1" />
</RelativeLayout>
我希望最终结果看起来像:
【问题讨论】:
-
在视图中获取文本视图
-
android:gravity="center"
-
android:layout_centerHorizontal="true" 在 TextView 中
-
您能否分享一张您正在寻找的参考图片?
-
视图不是 ViewGroup。意味着您不能在其中使用 TextView 或 Button。 View 和 ViewGroup 之间存在很大差异。参考这个stackoverflow.com/a/34676816/6176457@KrishnaJ
标签: android android-layout textview