简体   繁体   English

布局和活动有什么区别?

[英]What is the difference between layout and activity?

I have some problems with the layout and activity and I don't know are they different,are they related? 我在布局和活动方面存在一些问题,我不知道它们是否不同,是否相关? I think the layout is a place we can add or remove our views and activity is just a place that shows any thing in our layout, is this true? 我认为布局是一个我们可以添加或删除视图的地方,而活动只是一个在布局中显示任何内容的地方,这是真的吗?

An activity: 一个活动:

is an instance of Activity, a class in the Android SDK. 是Activity(Android SDK中的类)的实例。 An activity is responsible for managing user interaction with a screen of information. 活动负责管理用户与信息屏幕的交互。 You write subclasses of Activity to implement the functionality that your app requires. 您可以编写Activity的子类来实现应用程序所需的功能。 A simple application may need only one subclass; 一个简单的应用程序可能只需要一个子类。 a complex application can have many. 一个复杂的应用程序可以有很多。

A layout: 布局:

defines a set of user interface objects and their position on the screen. 定义一组用户界面对象及其在屏幕上的位置。 A layout is made up of definitions written in XML. 布局由用XML编写的定义组成。 Each definition is used to create an object that appears on screen, like a button or some text. 每个定义都用于创建出现在屏幕上的对象,例如按钮或一些文本。

A layout deals with the user interface. 布局处理用户界面。 Its where you set all your views that will be visible on the user interface. 您可以在其中设置所有视图,这些视图将在用户界面上可见。

The code behind (.java) sets the layout you created as the content view and manipulates the behavior of the views you have set. 后面的代码(.java)将您创建的布局设置为内容视图,并操纵已设置的视图的行为。 For example, sets the text for a text view. 例如,设置文本视图的文本。

The activity then is the whole thing, the layout and the code behind. 然后,活动就是整个过程,布局和背后的代码。

An activity is the java code which attaches actions and puts content to/in a layout. 活动是一种Java代码,它附加动作并将内容放置到布局中/中。 For this the Activity loads the layout. 为此,活动将加载布局。

Briefly, 简单地说,

Activity is the java part of your projects. 活动是项目的Java部分。 The program and any kind of algorithms are implemented here. 该程序和任何一种算法都在这里实现。 Also layout views come to life in an activity. 布局视图在活动中也变得生动起来。

Layout is where you organize the views in your page. 布局是组织页面视图的地方。 But without activity, they have no meaning. 但是没有活动,它们就没有意义。 Because in activity, you have to get these views and use them programmaticaly. 因为在活动中,您必须获取这些视图并以编程方式使用它们。

All together, you load views from layout to activity and in activies you implement your whole program. 总之,您从布局到活动都加载视图,然后在活动中实施整个程序。

A layout defines all the appearance of an app and this is of no use without a java program which helps in real functioning of that visual display. 布局定义了应用程序的所有外观,没有Java程序(这有助于视觉显示的实际功能)就毫无用处。 Thus we define what an app does by writing its java code and a special java class called activity decides which layout to use at a particular instant and tells the app how to respond to the user. 因此,我们通过编写应用程序的Java代码来定义应用程序的功能,一个名为活动的特殊Java类决定在特定时刻使用哪种布局,并告诉应用程序如何响应用户。

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

相关问题 this 和 Activity.this 有什么区别 - What's the difference between this and Activity.this 在Activity中声明最终变量并在onCreate方法上实例化它之间有什么区别? - What is the difference between declaring a final variable in an Activity and instantiating it on the onCreate method? 活动可见生命周期和前景生命周期之间有什么区别? - What is the difference between activity visible liftime and foreground lifetime? Activity 生命周期中的 onResume() 和 onPostResume() 有什么区别? - What is the Difference between onResume() and onPostResume() in Activity Life Cycle? Android 中扩展应用程序和扩展活动有什么区别? - What is the difference between Extends Application and Extends Activity in Android? Activity setTitle 与 Toolbar setTitle 有什么区别 - what is the difference between Activity setTitle vs Toolbar setTitle parsys组件和AEM中的响应式布局有什么区别 - What is the difference between parsys component and responsive layout in AEM layout:column和layout:columnSpan之间的区别 - Difference between layout:column and layout:columnSpan Java中&和&&有什么区别? - What is the difference between & and && in Java? += 和 =+ 有什么区别? - What is the difference between += and =+?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM