如何将一个物体放在屏幕的另一边?
2015-2-11 0:20:17
收藏:0
阅读:190
评论:3
我正在写一个移动应用开发课程的程序。该应用包含在屏幕上放置两个按钮。当我放置/2时,它会放置在中间,当我放置/3时,它会将按钮放置在屏幕左边的三分之一处。由于我需要两个按钮,因此我希望将一个放置在屏幕左侧的三分之一处(我知道如何做),另一个放置在屏幕右侧的三分之一处(我不知道怎样做)。我该怎么做?
我的代码段:
myRedButton.x = display.contentWidth /3
myRedButton.y = display.contentHeight -50
myGreenButton.x = display.contentWidth /2
myGreenButton.y = display.contentHeight -100
我还不太熟悉移动应用编程的场景,所以请简单说明。谢谢!
点赞
用户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
尝试一下:
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
评论区的留言会收到邮件通知哦~
推荐文章
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
我已经使用了权重来将屏幕分成三部分,并且在其中放置了按钮,请检查一下它是否有效。
<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>