相对布局覆盖在相对布局组件中声明的组件
作为一名 Android 开发人员,我是个新手,目前我正在了解relativelayout,但面临一个较小的问题,即 Textview 重叠在图像上。在这里,我向您提供我想要的图像和我得到的图像,以及我所做的很多代码。所以请帮助我。
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/firstImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/splash1" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@id/firstImage"
android:layout_alignBaseline="@id/firstImage"
android:text="@string/menu" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/splash1" />
</RelativeLayout>
这是我想要的布局图像。
请帮助我。
提前致谢..
I am very new in as a android developer and i am currently understanding the RelativeLayout but facing a smaller problem that Textview is overLapping on the Image. Here I am providing you the Image that what i want and what i am getting and also the code that much i have did. so please Help me.
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/firstImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/splash1" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@id/firstImage"
android:layout_alignBaseline="@id/firstImage"
android:text="@string/menu" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/splash1" />
</RelativeLayout>
Here is the Image that i want in layout.
Please Help me.
Thanks in Advance..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用这些属性
进行文本视图..
检查此代码
use these property
for text view..
check this code
将您的 xml 文件代码替换为以下内容...
replace your xml file code with this...
您可以切换到图形模式并修复上述问题。这并不是说您必须直接在 XML 中定义所有内容,但您可以切换到图形模式并修复此问题。
You can switch to graphic mode and fix the above. It is not that you have to define every thing in XML directly but you can switch to graphic mode and fix this.
添加两个 TextView 属性
android:layout_centerHorizontal="true"
和android:gravity="center"
,这样文本就会在 TextView 中居中。如果文本太大(它会与图像重叠),则可能会出现问题。为了避免这种情况,您应该像这样定义布局:
注意,两个图像视图是如何在 TextView 之前定义的。这是因为这些图像视图将成为您的锚视图,这意味着其他所有内容都将根据它们进行对齐。您的 TextView 现在位于 2 个 ImageView 之间,因此无论有什么文本,它都不会重叠任何内容。
Add two more properities of textview
android:layout_centerHorizontal="true"
andandroid:gravity="center"
, so text will be centered inside yout TextView.In this there might be a problem if text is too big (it will overlap the images). To avoid that you should define your layout like that:
Notice, how both image views are defined before TextView. That's because those image views will be your anchor views, meaning everything else will be aligned depending on them. Your TextView is now between 2 ImageViews so no matter what text there is, it will not overlap anything.