Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 想在同一屏幕上做两个不同的活动吗_Android - Fatal编程技术网

Android 想在同一屏幕上做两个不同的活动吗

Android 想在同一屏幕上做两个不同的活动吗,android,Android,我想在同一屏幕上做两个不同的活动。我知道fragment,但当我们使用fragment时,10英寸桌子显示不同的UI,4.6英寸手机显示不同的UI。但我希望我的屏幕总是通过在横向模式下将屏幕分成两个相等的部分来打开,并且我可以在屏幕的两个相等部分中进行不同的活动。我搜索了很多,但没有找到适合我问题的答案 事实上,我想在屏幕的一半为用户开发一个游戏,另一半为计算机Android操作系统开发一个游戏。通过权重属性可以实现等分 我假设您非常熟悉片段,所以我只告诉您xml部分,您的屏幕将被划分为两个相等

我想在同一屏幕上做两个不同的活动。我知道fragment,但当我们使用fragment时,10英寸桌子显示不同的UI,4.6英寸手机显示不同的UI。但我希望我的屏幕总是通过在横向模式下将屏幕分成两个相等的部分来打开,并且我可以在屏幕的两个相等部分中进行不同的活动。我搜索了很多,但没有找到适合我问题的答案


事实上,我想在屏幕的一半为用户开发一个游戏,另一半为计算机Android操作系统开发一个游戏。

通过权重属性可以实现等分

我假设您非常熟悉片段,所以我只告诉您xml部分,您的屏幕将被划分为两个相等的片段

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<fragment android:name="com.example.android.fragments.Fragment1"
          android:id="@+id/headlines_fragment"
          android:layout_weight="1"
          android:layout_width="match_parent"
          android:layout_height="0dp" />

<fragment android:name="com.example.android.fragments.ArticleFragment"
          android:id="@+id/article_fragment"
          android:layout_weight="1"
          android:layout_width="match_parent"
          android:layout_height="0dp" />
这将把您的屏幕分为两部分,并在不同的片段中介绍不同的UI

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<fragment android:name="com.example.android.fragments.Fragment1"
          android:id="@+id/headlines_fragment"
          android:layout_weight="1"
          android:layout_width="match_parent"
          android:layout_height="0dp" />

<fragment android:name="com.example.android.fragments.ArticleFragment"
          android:id="@+id/article_fragment"
          android:layout_weight="1"
          android:layout_width="match_parent"
          android:layout_height="0dp" />

您可以将单个xml文件膨胀为多个片段类,从而实现相同的UI。Android活动不是设计为一次显示两个。一个活动-一个应用程序屏幕。如果您想要实现您所描述的,那么使用片段和Android布局系统,该系统允许使用smallestWidth属性为不同屏幕大小的设备提供单独的布局。看看这篇文章。Android拥有非常强大的资源布局、维度等管理系统,请使用它。

@2Dee。。你读过我的问题吗?是的,我看到你的问题没有提供足够的信息,甚至没有开始给你建设性的解决方案,所以我说了显而易见的。屏幕上不可能同时有两个活动,所以您应该使用片段和布局缩放到不同的屏幕或不同的布局来支持不同的屏幕大小。但是你已经知道了,因为你已经阅读了官方文档,对吗?你已经清楚地表明,你不知道Android是如何工作的,在最基本的层面上。我建议你实际阅读文档。谢谢你的回复……它和10英寸和4.6英寸的android设备一样工作吗?他想在他的应用程序中使用两个活动,它是impossible@ThanhLe这就是为什么我要告诉他这些碎片Approach@BlueGreen是的,它将工作,但与碎片的方法。您不能在同一时间内只有一项活动foreground@BlueGreen:如果你认为你需要两项活动,我建议你重新考虑你的设计。为此,您需要使用Fragment,这就是它的设计目的。移动设备上的屏幕空间已经有限,因此,设计选择不支持共享屏幕的多个活动。