0

我有一个 android 布局,其中有一些其他随机的东西,在中间部分我有一个 linearLayout,它包含 4 个 RelativeLayout,如下面的 XML 代码。

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left|center_vertical"
        android:background="@drawable/backgroudpng">

    </RelativeLayout>
</LinearLayout>

话虽如此,当我尝试将对象放在这种相对布局中时,这会走下坡路。当我在其中放置一个对象时,它会将对象放置在布局的另一部分(而不是我将它拖到的位置!)。因此,例如,如果我将一个文本框放到相对布局的右上角,它可能会将它放在右下角,或者在中心......

我需要让这个工作,或者我需要一种不同的方法。我的目标是创建一个自定义按钮,让我可以同时在其上显示三个或四个不同的文本对象。

我想要做什么(如果你也需要我,我可以在 gimp 中画出来)

______________________________________________________________________________________
|                                                                                     |
|  Some information here                                                              |
|                                               picture of a number from 1-10 here    |
|  Something else about the "button here"                                             |
|                                                                                     |
|_____________________________________________________________________________________|

无论如何,我正在考虑使用表面视图来执行此操作,但这似乎有点矫枉过正。基本上,我只想创建 4 个这样的大型可点击界面,显示他们可以通过点击设置的一些设置。无论如何,如果这是错误的方法,请告诉我!尽管这似乎是一种简单的方法,但这正是我所希望的!

更新:

这是我正在尝试完成的工作的快速图片:

在此处输入图像描述

浅棕色代表背景图像,黑色代表整个视图的背景,然后文本只是示例文本。我希望他们能够像按钮一样单击此视图并更改这些设置背后的设置。我遇到的问题是我将一个小文本对象拖到我想要“类型”设置的位置,当我放手时,它被定位在“行影响”应该是的位置。

今晚我将尝试以下建议的方法,看看它们是否能解决问题。

感谢您一直以来的帮助!

更新 2:

这是代码,以及它产生的图片(我已经验证它在我的手机以及另一部手机和模拟器上看起来像这样)

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/buttonbackground">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="Small Text"
        android:id="@+id/textView"
        android:textColor="#debabc"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="20dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="Small Text"
        android:id="@+id/textView2"
        android:layout_marginRight="21dp"
        android:textColor="#dec1db"
        android:layout_below="@+id/textView3"
        android:layout_alignParentRight="true"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="Small Text"
        android:id="@+id/textView3"
        android:textColor="#debabd"
        android:layout_alignBaseline="@+id/textView"
        android:layout_alignBottom="@+id/textView"
        android:layout_toLeftOf="@+id/textView2"/>
</RelativeLayout>

在此处输入图像描述

蓝色框大致是我放置文本的位置,尽管为了清楚起见,它们在 X 和 Y 通道上都重新定位。

此外,这是使用 Android Studio,但我在 eclipse 中检查并加载了布局,它也在做同样的事情。这很奇怪,因为我以前使用过它们并且没有遇到过这个问题......我一定做错了什么。

附加信息:尝试使用 API14、16 和 18 渲染它。

再次感谢!

4

2 回答 2

1

使用相对布局作为根布局,而不是您使用的线性布局。它将使您更容易管理其他布局。

于 2013-10-15T03:33:58.377 回答
0

根本不要使用RelativeLayout。根据您的要求。具有两行的表格布局提供了更好的结果。它也很容易使用。它不会弄乱您在不同屏幕尺寸下的布局。

于 2013-10-15T04:03:43.740 回答