Android 如何将文本视图放置在ImageView的顶部
有没有一种简单的方法可以将文本视图放在ImageView的顶部 我的代码:Android 如何将文本视图放置在ImageView的顶部,android,android-layout,Android,Android Layout,有没有一种简单的方法可以将文本视图放在ImageView的顶部 我的代码: <ImageView android:layout_width="120dp" android:layout_height="120dp" android:src="@drawable/finaloval" android:elevation="10dp" android:layout_centerHorizontal="true" android:id="@+id/
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@drawable/finaloval"
android:elevation="10dp"
android:layout_centerHorizontal="true"
android:id="@+id/greencircleId"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:id="@+id/textView"
android:textSize="40sp"
android:textColor="@color/colorAccent" />
绿色圆圈将是我的@drawable/finaloval。而100%的有机将是文本视图 尝试将imageview设置为textview的背景 你想在一张图片或一张清晰的绘图纸上加上一些文字吗 我将使用可绘制的形状来制作示例 现在我有一个这样的形状:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
>
<size
android:height="100dp"
android:width="100dp"
/>
<solid
android:color="#66ccff"
/>
</shape>
然后将其设置为布局xml中文本视图的背景
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/circle"
android:text="Hello World!"
/>
看起来是这样。这是一个100dp*100dp的。
并尝试修改textview的宽度和高度
<TextView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="@drawable/circle"
android:text="Hello World!"
/>
现在看起来像这样。大得多。
因此,结论是:
- 更改drawable的大小,并在布局xml中使用wrap_内容
- 更改布局xml中的“布局宽度”和“布局高度”
很抱歉,我在回答之前没有违背规则(因为这是我的第一个答案)。只需使用
线性布局作为根,然后从上到下重新排列视图,这意味着在您的情况下应该是文本视图
然后图像视图
根据评论编辑
要进行视图重叠,可以使用其他人建议的RelativeLayout
或FrameLayout
试试这个:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text"
android:layout_marginTop="23dp"
android:id="@+id/textView"
android:textSize="40sp"
android:textColor="@color/colorAccent" />
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@drawable/finaloval"
android:elevation="10dp"
android:id="@+id/greencircleId"/>
</RelativeLayout>
我认为这是最简单的方法。希望这有帮助
<TextView android:id="@+id/tv_versionstatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="5dp"
android:drawableBottom="@drawable/icon_new"
android:text="text"
android:textColor="#363636"
android:textSize="20sp" />
drawableBottom也是您的选择请尝试为布局设置背景,并将您的文本视图放在其中,我已根据您在示例中共享的图像对其进行了编码
Please try to set the background for the layout and place your textviews inside that , i have coded it as per the image you shared in it example
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:background="@drawable/finaloval">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100% natural"
android:layout_marginTop="23dp"
android:id="@+id/natural"
android:textSize="20sp"
android:textColor="@color/colorAccent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="organic"
android:layout_marginTop="23dp"
android:layout_below="@id/"
android:id="@+id/natural"
android:textSize="40sp"
android:textColor="@color/colorAccent" />
</RelativeLayout>
试试这个xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@drawable/finaloval"
android:layout_gravity="center"
android:elevation="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text"
android:textSize="40sp"
android:layout_gravity="center"
android:textColor="@color/text_black" />
</FrameLayout>
尝试使用框架布局作为您的root@juanCruzSoler. 我试过了,但没用。谢谢,在回答中添加一些解释,说明此回答如何帮助OP解决当前问题,但如何修改图像的大小?我试图更改xml文件的高度和宽度,但它没有更改实际主文件的大小。xml@KidM谢谢,这很有效。我刚刚删除了“你能告诉我你所说的“在ImageView上放置文本视图”是什么意思吗?一张简单的画@AliStill图像位于文本视图的右侧。无论如何,谢谢你的帮助!谢谢你,这一切都成功了。但是如何更改finaloval.xml的大小呢?我试过android:hight和android:width,但它没有改变它的大小。请接受答案,要改变椭圆形大小,请尝试添加填充,无论你是否需要顶部、左底部或右侧的空间。如果你有扭曲内容,请尝试添加相对布局的宽度高度