如何将一个物体放在屏幕的另一边?

我正在写一个移动应用开发课程的程序。该应用包含在屏幕上放置两个按钮。当我放置/2时,它会放置在中间,当我放置/3时,它会将按钮放置在屏幕左边的三分之一处。由于我需要两个按钮,因此我希望将一个放置在屏幕左侧的三分之一处(我知道如何做),另一个放置在屏幕右侧的三分之一处(我不知道怎样做)。我该怎么做?

我的代码段:

myRedButton.x = display.contentWidth /3
myRedButton.y = display.contentHeight -50
myGreenButton.x = display.contentWidth /2
myGreenButton.y = display.contentHeight -100

我还不太熟悉移动应用编程的场景,所以请简单说明。谢谢!

点赞
用户1023164
用户1023164

我已经使用了权重来将屏幕分成三部分,并且在其中放置了按钮,请检查一下它是否有效。

<LinearLayout
    android:id="@+id/lnrLeftContent"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="0.33"
    android:gravity="center"
    android:orientation="vertical" >

    <Button
        android:id="@+id/btnLeft"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

<LinearLayout
    android:id="@+id/lnrCenterContent"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="0.33"
    android:gravity="center"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/btnLeft"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

<LinearLayout
    android:id="@+id/lnrRightContent"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="0.33"
    android:gravity="center"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/btnLeft"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>
2014-01-23 05:04:46
用户88888888
用户88888888

在这里,我放了三个 TextView,你可以按自己的喜好将其改为按钮。这将在屏幕上放置三个视图,占用相同的空间。

<LinearLayout android:id="@+id/total_row_holder"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="3dp"
    android:orientation="horizontal" >

    <TextView android:id="@+id/total_textview"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="一些其他的"
        android:padding="2dp"
        android:layout_gravity="center"
        android:background="#e8f4f9"
         />

    <TextView android:id="@+id/total_value_textview"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_marginLeft="1dp"
        android:text="你知道的"
        android:padding="2dp"

        android:background="@android:color/white" />

    <TextView android:id="@+id/net_value_textview"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="1dp"
        android:layout_weight="1"
        android:text="一些值"
        android:padding="2dp"

        android:background="@android:color/white" />

</LinearLayout>
2014-01-23 06:15:43
用户1979583
用户1979583

尝试一下:

local myGreenButton = display.newRect(0,0,50,50)
myGreenButton.x = display.contentWidth- (display.contentWidth/3)
myGreenButton.y = 100

或者也可以这样简单写:

local myGreenButton = display.newRect(0,0,50,50)
myGreenButton.x = (2/3)*display.contentWidth
myGreenButton.y = 200

继续编程.............. :)

2014-01-23 18:55:09