[英]Preventing TextView and ImageView Overlap In Relative Layout
I have a textView ( titleTv
) and an imageView ( buyButton
) which are sometimes have an overlap if the titleTv
has a somewhat long name. 我有一个
titleTv
( titleTv
)和titleTv
( buyButton
),如果titleTv
名称有点长,有时会重叠。
How might this be prevented? 如何预防? I understand this can be done using an external library - but it seems strange there isn't a simple way to accomplish this.
我知道可以使用外部库完成此操作-但似乎没有一种简单的方法可以完成此操作,这很奇怪。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="7dip"
android:paddingTop="7dip" >
<TextView
android:id="@+id/titleTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/white"
android:paddingLeft="5dp"
android:text=""
android:textSize="20sp" />
<TextView
android:id="@+id/uploaderTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/titleTv"
android:paddingLeft="5dip"
android:paddingTop="5dp"
android:textColor="@color/verylightgrey"
android:textSize="16sp" />
<TextView
android:id="@+id/viewCountTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/titleTv"
android:layout_toRightOf="@id/uploaderTv"
android:paddingTop="5dp"
android:textColor="@android:color/black"
android:textSize="16sp" />
<ImageView
android:id="@+id/buyButton"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:paddingTop="7dip"
android:src="@drawable/buy_a_up_btn" />
</RelativeLayout>
(the overlapping fields are the video's title and the $ button) (重叠的字段是视频的标题和$按钮)
http://i.stack.imgur.com/clpNv.png http://i.stack.imgur.com/clpNv.png
Try this: 尝试这个:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="7dip"
android:paddingTop="7dip" >
<ImageView
android:id="@+id/buyButton"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:paddingTop="7dip"
android:src="@drawable/buy_a_up_btn" />
<TextView
android:id="@+id/titleTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/buyButton"
android:background="@color/white"
android:paddingLeft="5dp"
android:text=""
android:textSize="20sp" />
<TextView
android:id="@+id/uploaderTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/titleTv"
android:paddingLeft="5dip"
android:paddingTop="5dp"
android:textColor="@color/verylightgrey"
android:textSize="16sp" />
<TextView
android:id="@+id/viewCountTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/titleTv"
android:layout_toRightOf="@id/uploaderTv"
android:paddingTop="5dp"
android:textColor="@android:color/black"
android:textSize="16sp" />
</RelativeLayout>
just add your ImageView
below that TextView
. 只需将您的
ImageView
添加到该TextView
之下。 Add this attribute in your ImageView declaration 在您的ImageView声明中添加此属性
android:layout_below="@+id/titleTv"
Now the xml should be like this: 现在,xml应该是这样的:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="7dip"
android:paddingTop="7dip" >
<TextView
android:id="@+id/titleTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/white"
android:paddingLeft="5dp"
android:text=""
android:textSize="20sp" />
<TextView
android:id="@+id/uploaderTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/titleTv"
android:paddingLeft="5dip"
android:paddingTop="5dp"
android:textColor="@color/verylightgrey"
android:textSize="16sp" />
<TextView
android:id="@+id/viewCountTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/titleTv"
android:layout_toRightOf="@id/uploaderTv"
android:paddingTop="5dp"
android:textColor="@android:color/black"
android:textSize="16sp" />
<ImageView
android:id="@+id/buyButton"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_below="@+id/titleTv"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:paddingTop="7dip"
android:src="@drawable/buy_a_up_btn" />
</RelativeLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.