android - 位于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
请指导我,建议我并解决这个问题,如果您对我的问题有任何疑问,请询问我。谢谢。
解决方案
使用这个我希望它会像魅力一样工作。像下面一样为 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>
推荐阅读
- reactjs - 在 redux 商店中存储授权标志是否安全
- google-app-engine - 具有 python 3.7 标准环境和端点的 Google 应用程序引擎
- neo4j - 删除 Neo4J 中以特定节点开始和结束的所有节点
- android - 如何在活动中包含底部导航视图布局,使其显示在列表视图项下方?
- excel - 使用密码保护工作簿,复制到新目的地
- excel - WorksheetChangeEvents 函数在运行时可能会错过事件吗?
- python - 如何修改 Matplotlib 直方图的输出以创建新的修改直方图(不丢失同步)
- angular-cli - 如何使用 Angular 6 添加 BrowserSync?
- mysql - MySQL关于重复键更新从查询中添加值
- c# - 建立与 SQL Server.Asp.net 的连接时发生与网络相关或特定于实例的错误