[英]How to start a new android activity that is smaller than the full screen
For a current android application I'm developing, I need to display some integer values on the screen after the user clicks a set of buttons. 对于我正在开发的当前android应用程序,我需要在用户单击一组按钮后在屏幕上显示一些整数值。 Essentially, I want to have a blocked space on the screen that will always display the numbers.
本质上,我希望屏幕上有一个始终显示数字的空白区域。
I'm at a loss for how to approach this problem, I originally just made use of the toast function for the display but that only lasts for a few seconds and doesn't change as buttons are pressed live. 我对如何解决这个问题一无所知,我最初只是在显示屏上使用了Toast功能,但仅持续几秒钟,并且不会因实时按下按钮而改变。
Instead, I've been attempting to create a new activity which will only take up a fraction of the screen (maybe the top 10%). 相反,我一直在尝试创建一个新的活动,该活动仅占屏幕的一小部分(可能是前10%)。 I know how to create a new Android Activity which opens a new page, but is there any way to create an activity that can overlay on the current page, and is smaller than the screen size?
我知道如何创建一个新的Android活动来打开一个新页面,但是有什么方法可以创建一个可以覆盖当前页面并且小于屏幕大小的活动?
Thanks so much. 非常感谢。
Don't create an additional Activity
. 不要创建其他
Activity
。 Use the same Activity
that your buttons are on. 使用与按钮相同的
Activity
。
You can add a TextView
to your display that can be used for displaying the values and/or text (Position it on the screen how you want, and you can also set the desired size). 您可以将
TextView
添加到显示中,以用于显示值和/或文本(将其放置在屏幕上所需的位置,也可以设置所需的大小)。 This isn't the only option, but is pretty simple to use. 这不是唯一的选择,但是使用起来非常简单。
You can then add in methods to generate a String
based off of the actions performed on the buttons. 然后,您可以添加方法以根据对按钮执行的操作来生成
String
。 After generating the String
, you can update the text of the TextView
with it. 生成
String
,可以使用它更新TextView
的文本。
Use Fragments. 使用片段。 It Has its own Life Cycle works similar to a Activity-
它有自己的生命周期,类似于活动-
http://developer.android.com/training/basics/fragments/creating.html http://developer.android.com/training/basics/fragments/creating.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.