简体   繁体   English

相对布局压缩子视图

[英]Relative Layout squishing child views

I have an ImageView and TextView inside a RelativeLayout to move them all around as a group that sticks together. 我在RelativeLayout中有一个ImageView和TextView,将它们作为一个整体粘在一起移动。 It looks fine in the Graphical Layout inside Eclipse. 在Eclipse内的图形布局中看起来不错。

(The blue shows the outline for the RelativeLayout): (蓝色显示了RelativeLayout的轮廓):

在此处输入图片说明

However when I run the app, the child views appear squished toghether or on top of each other. 但是,当我运行该应用程序时,子视图会挤在一起或彼此叠在一起。 The ImageView doesn't even show anymore. ImageView甚至不再显示。 I'm not sure why this occurs? 我不确定为什么会这样?

在此处输入图片说明

XML XML

<RelativeLayout
    android:id="@+id/frameB"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/squashcourt"
    android:layout_alignLeft="@+id/squashcourt"
    android:layout_marginBottom="8dp"
    android:layout_marginLeft="8dp"
    android:clickable="true"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tv_aboveB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_margin="3dp"
        android:clickable="true"
        android:text="Robin"
        android:textAllCaps="true"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="@color/Red"
        android:textStyle="bold" />

    <ImageView
        android:id="@+id/btn_B"
        android:layout_width="115dp"
        android:layout_height="115dp"
        android:layout_below="@+id/tv_aboveB"
        android:layout_centerHorizontal="true"
        android:layout_margin="3dp"
        android:clickable="true"
        android:scaleType="fitXY"
        android:src="@drawable/b_left" />

</RelativeLayout>

I'm using a Samsung S4. 我正在使用三星S4。 Can anyone suggest something? 有人可以建议吗? Thanks in advance! 提前致谢!

You can Use simply TextView with bottom drawable . 您可以将TextView与底部drawable一起使用。

 <TextView
        android:id="@+id/tv_aboveB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:text="Robin"
        android:drawableBottom="@drawable/ic_launcher"
        android:textAllCaps="true"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="#ff0000"
        android:textStyle="bold" />

Now you can move the TextView any where on the screen. 现在,您可以将TextView移动到屏幕上的任何位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM