android – 防止在RelativeLayout中重叠的视图

我正在尝试开发一个 Android应用程序,但我在GUI设计中遇到了一些问题.屏幕截图的以下部分是我的问题(红色和蓝色线是由Android调试选项生成的).

这是代码

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/caption"
    android:layout_below="@+id/caption" >

    <ImageButton
        android:id="@+id/button_edit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_alignParentRight="true"
        android:src="@drawable/content_edit"
        style="?android:attr/borderlessButtonStyle" />

    <TextView
        android:id="@+id/myText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:text="@string/num_placeholder"
        android:textAppearance="?android:attr/textAppearanceLarge" />


</RelativeLayout>

您可以看到,TextView myText与ImageButton button_edit重叠.
一个简单的解决方案是使用LinearLayout而不是RelativeLayout.问题是:

>我需要右边的编辑按钮
>我需要文本填写剩下的布局(在编辑按钮的左边显然)

我也试图将myText的layout_width设置为“fill_parent”,但它会填充编辑按钮左侧的屏幕的其余部分.

预期的行为将是myText增加其高度(成为两行TextView),而不是重叠’button_edit’

有人可以帮我吗谢谢

解决方法

在TextView布局中使用layout_toLeftOf

喜欢这个:

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/caption"
android:layout_below="@+id/caption" >

<ImageButton
    android:id="@+id/button_edit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_alignParentRight="true"
    android:src="@drawable/content_edit"
    style="?android:attr/borderlessButtonStyle" />

<TextView
    android:id="@+id/myText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:text="@string/num_placeholder"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:layout_toLeftOf="@+id/button_edit" />

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...