- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我刚刚开始学习 android,我有一个应用程序,它的主要 Activity 使用 fragment 管理器在启动时添加了一个 fragment 。然后程序在两个 fragment 之间切换以执行其功能,再次使用 fragment 管理器来替换 fragment 。
我希望此应用在大屏幕上同时显示两个 fragment 。我该怎么办
A)检测到有大屏幕
和
B) 如果是这种情况,主要 Activity 是否将两个 fragment 加载到单个 Activity 中?
每个 fragment 都有布局,主要 Activity 有一个布局,它只是一个空白的框架布局,在 onCreate 期间用 fragment 填充。请记住:有两个 fragment 和一个 Activity 。 Activity 使用 fragment 管理器将 fragment 加载到其容器中。
最佳答案
A) 要检测大屏幕,您可以使用此代码
public static boolean isTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK)
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
如果设备在大屏幕上运行,它将返回 true。还要检查 this link
B) 通过代码添加 fragment ,您可以在同一 Activity 中拥有两个 fragment 。在主布局中有 2 个布局,它们将是两个 fragment 的容器。如果屏幕尺寸适合您,然后通过代码将 fragment 添加到每个 fragment 中。使用此代码。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent">
<RelativeLayout
android:id="@+id/FragmentContainer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RelativeLayout
android:id="@+id/FragmentContainer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
然后添加Fragments。
fragmentTransaction.add(R.id.FragmentContainer1, fragment);
fragmentTransaction.add(R.id.FragmentContainer2, fragment);
检查 this link获取 Lars Vogel 的精彩教程。
关于android - 在大屏幕上动态显示 Activity 中的两个 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24570114/
是否可以在 android list 文件中禁用对超大屏幕的支持?我们已经开发了一个应用程序,但还没有改变平板电脑的设计,所以我们想在以后的版本中禁用平板电脑支持。 我们使用 phonegap/htm
我查到的信息:320dp:典型的手机屏幕(240x320 ldpi、320x480 mdpi、480x800 hdpi 等)。480dp:类似 Streak 的补间数位板 (480x800 mdpi)
我创建了 4 个不同的布局文件并将它们放在 layout , layout-small,layout-large,layout-xlarge. 文件夹和在 QVGA、HVGA 和 WXGA 仿真器中测
我有一个名为 showPage 的节目转场从 View Controller 到 TableView Controller ,我正在调用 performSegueWithIdentifier()在单击
我是一名优秀的程序员,十分优秀!