在Android的应用程序时,应该使用片段?为什么使用片段?片段、应用程序、Android

2023-09-12 04:00:15 作者:酒蚀离心人

这似乎是一个愚蠢的问题。我知道为什么使用片段和Android开发者网站很好解释了这一点。但在大多数情况下,我想在平板电脑的不同部分有自己特殊的行为和用户界面,我不知道该怎么片段可以提供帮助。在大多数情况下,我认为这是更快地创建2个不同的活动(1片,1个用于手机),并在第三类有着共同的行为和事件。 所以牢记这一点我为什么要使用片段?

It seems a stupid question. I know why to use fragments and the Android developer site good explains this. But in most cases I want on the tablets the different parts to have their own special behavior and UI and I don't know how fragments can help. In most cases I think it's quicker to create 2 different Activities (1 for tablets and 1 for handsets) and to share the common behaviors and events in a third class. So keeping this in mind why should I use fragments ?

推荐答案

片段在我看来更多的是失业保险金。这是方便用户有时会看到同样的屏幕上的两个不同类别的两种不同的观点。如果在你的创造力的那一刻,你决定这将是很好,显示着,比方说,一个ListView,占用了一半的屏幕和一个web视图,占用了另一半的你的应用程序 - 这样,当你点击一个列表项A片段传递的意图,在B片段web视图,突然你看你刚才点击没有什么应用程序切换活动 - 那么你可以使用一个片段。这只是一个例子,我想出了我的头顶。

Fragments are more of a UI benefit in my opinion. It's convenient for the user sometimes to see two different views of two different classes on the same screen. If, in your moment of creativity, you decide it would be nice to display your application with, say, a listView that takes up half the screen and a webView that takes up the other half - so that when you click on a list item in fragment A it passes an intent to the webView in fragment B, and suddenly you see what you just clicked without the app switching activities - then you could use a fragment. That's just an example I came up with off the top of my head.

底线:片段是屏幕在同一时间上的两个或更多的活动

Bottom line: Fragments are two or more activities on the screen at the same time.