首页 > 解决方案 > 位于imageview Android下方中心的Textview

问题描述

你今天过得怎么样。

我想知道我今天卡在哪里。我在列表中获取图像和文本的 json,我的图像是圆形的。当我得到带有文本的图像时,它看起来很糟糕,因为文本不在 imageview 下方的中心。我搜索了很多对此,但我没有找到。我只是在父级“真”中找到了重力“中心”和中心,我尝试了这两个但我没有得到解决方案。我的代码是:-

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity>


<de.hdodenhof.circleimageview.CircleImageView
    android:layout_width="110dp"
    android:layout_height="110dp"
    android:layout_marginTop="70dp"
    android:layout_marginStart="15dp"
    android:id="@+id/img_design" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/img_design"
    android:id="@+id/design_color"
    android:text=" "
    android:layout_centerInParent="true"
    android:textStyle="bold"
    android:textSize="15sp" />
</RelativeLayout>

我想在图像中间自动设置这样的文本,因为文本的长度不是固定的:

         IMAGEVIEW
           text

请指导我,建议我并解决这个问题,如果您对我的问题有任何疑问,请询问我。谢谢。

标签: androidandroid-layoutandroid-imageviewtextview

解决方案


使用这个我希望它会像魅力一样工作。像下面一样为 imageview 和 textview 创建和分离父级,然后尝试.. 使用您自己正在使用的圆形 imageview

在此处输入代码//schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android .com/tools" android:layout_width="match_parent"

android:layout_height="wrap_content">


<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

<ImageView
    android:id="@+id/img_design"
    android:layout_width="110dp"
    android:layout_height="110dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:src="@color/white"
      />

<TextView
    android:id="@+id/textView7"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="16dp"
    android:text="TextView"
     android:layout_centerInParent="true"
    android:layout_below="@+id/img_design" />
</RelativeLayout>


推荐阅读