【发布时间】:2014-09-12 12:17:29
【问题描述】:
我现在正在创建一个 Android 应用程序,并且我有一个框架,其中外壳包含片段。到目前为止一切正常,但我遇到了一个我无法完全理解的问题。
我有一个 Frame,它是整个屏幕(FrameLayout - 我应该使用 FrameLayout 作为主 Frame 吗?)并且在这个 Frame 内部有一些片段会根据用户的交互而改变。这些片段位于 .xml 文件 FrameLayouts 中。我现在想知道它们是否可以或应该是 FrameLayouts 或 Fragments...我创建了一个 Google Maps frgment,它是一个 Fragment ideed,这让我思考。
所以我的问题是:它是否会产生影响或对性能有任何影响,或者我可以简单地使用任何符合其目的的东西吗?
为了说明我的意思,这里有一些代码示例: (FrameLayout里面FrameLayout里面都是放的fragment)
主框架(activity_main.xml):
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="MergeRootFrame" >
<FrameLayout
android:id = "@+id/mainFrame"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:layout_marginBottom = "@dimen/bottom_Main_Tabs">
</FrameLayout>
<LinearLayout
android:layout_width = "match_parent"
android:layout_height = "@dimen/bottom_Main_Tabs"
android:layout_gravity = "bottom"
android:background="@color/grey2"
>
<ImageButton
android:id = "@+id/bottomButton_home"
android:layout_height = "match_parent"
android:layout_width = "0dp"
android:layout_weight = "1.0"
android:layout_marginLeft = "2dp"
android:layout_marginRight = "2dp"
android:background = "@drawable/ic_home_white"
android:onClick = "openHome"
/>
[...]
</LinearLayout>
<RelativeLayout
android:id = "@+id/TopBar"
android:layout_width = "match_parent"
android:layout_height = "@dimen/top_Bar_Hight"
android:layout_gravity="top"
android:background="@color/grey_transparentBy50"
>
<ImageView
android:id= "@+id/TopBarLogo"
android:layout_width = "@dimen/top_Bar_Hight"
android:layout_height = "@dimen/top_Bar_Hight"
android:background="@drawable/ic_launcher"
/>
[...]
</RelativeLayout>
</FrameLayout>
一个片段(FrameLayout:)
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/home_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blue"
tools:context="com.domain.app.HomeFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:textSize="100sp"
android:text="Home" />
</FrameLayout>
另一个片段(片段)
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context="com.domain.app.MapsActivity"
android:name="com.google.android.gms.maps.MapFragment"
tools:layout = "@layout/activity_main"
/>
GoogleMaps 实现也有问题,但我还没有花足够的时间在这里寻求帮助。
提前致谢。
约翰
【问题讨论】:
-
你能粘贴xml文件的内容吗?
标签: java android performance fragment android-framelayout