java如何更改以不同显示大小显示片段的方式?
我目前正在为Android
设备制作一个应用程序,我想知道如何更改fragments
在不同显示尺寸(例如平板电脑)中的显示方式
此时,我的所有片段都有一个活动,这导致我在更改页面时替换fragments
,但对于平板电脑,我希望在该activity
内显示2个片段
我已经为我的主要活动创建了一个布局大版本:
<?xml version="1.0" encoding="utf-8"?>
<安卓.support.constraint.ConstraintLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:app="http://schemas.安卓.com/apk/res-auto"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".PaginaInicial"
tools:showIn="@layout/app_bar_pagina_inicial">
<LinearLayout
安卓:orientation="horizontal"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent">
<fragment
class="pt.ipp.estg.schoolhelperapp.apontamento.ListaApontFragment"
安卓:id="@+id/a_fragment"
安卓:layout_weight="1"
安卓:layout_width="0dp"
安卓:layout_height="match_parent" />
<fragment
class="pt.ipp.estg.schoolhelperapp.apontamento.VerApontFragment"
安卓:id="@+id/b_fragment"
安卓:layout_weight="2"
安卓:layout_width="0dp"
安卓:layout_height="match_parent" />
</LinearLayout>
</安卓.support.constraint.ConstraintLayout>
片段容器位于主活动的小版本中
其中一个片段显示项目列表(@+id/a_fragment)
,另一个片段显示我先前选择的一个特定项目的信息(@+id/b_fragment)
# 1 楼答案
有关更多详细信息,请参阅本文件:https://developer.android.com/training/multiscreen/screensizes