【问题标题】:How can I center my textView in the middle of my ImageView?如何将我的 textView 居中于 ImageView 的中间?
【发布时间】:2014-03-26 22:18:58
【问题描述】:

我想将 textView 垂直和水平居中。现在我的 imageView 的左角有 textView。非常感谢

<RelativeLayout
    android:layout_width="0dp"
    android:layout_height="70dp"
    android:layout_weight="3" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="0dp"
        android:src="@drawable/numero" />

    <TextView
        android:id="@+id/list_item_numero"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:textSize="15sp"
        android:gravity="center" />
</RelativeLayout>

【问题讨论】:

  • 使用 android:layout_centerInParent="true",因为您的 ImageView 似乎占据了您的整个布局

标签: android textview imageview center gravity


【解决方案1】:

使用RelativeLayout 很简单!

<TextView
        android:id="@+id/list_item_numero"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:textStyle="bold"
        android:textSize="15sp"
        android:gravity="center" />

顺便说一句,使用RelativeLayout时不必使用android:layout_weight

【讨论】:

    【解决方案2】:

    将以下内容添加到您的文本视图中

    android:layout_centerInParent="true"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-05
      相关资源
      最近更新 更多