android - android studio设计时不显示fragment的结构,只显示阴影。设计时如何获取原始fragment?
问题描述
在设计主要活动时,我尝试添加两个片段。但是在activity_main的设计选项卡中没有显示片段的原始结构,而是为每个片段显示了阴影区域。在设计过程中如何获得片段的原始结构? 在此处输入图像描述
解决方案
在您的 activity_main.xml 中,确保您的每个片段标签都指定:
android:name
有你的片段的路径tools:layout
与片段的布局
如果您使用的是包含标签,那么您需要在片段中使用类似tools:showIn=".MainActivity"
( docs ) 的内容。
这是一个例子:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity">
<fragment android:name="com.example.FirstFragment"
android:id="@+id/firstFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout="@layout/fragment_first" />
<fragment android:name="com.example.SecondFragment"
android:id="@+id/secondFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout="@layout/fragment_second" />
</LinearLayout>
fragment_first.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".FirstFragment">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>
推荐阅读
- reactjs - 如何在 ReactJS 中使用默认值编辑输入
- c# - 丢弃和不分配变量有什么区别?
- html - Angular 指令 - 动态创建组件和包装内容
- python - 将坐标打印到带有数据的 csv 文件
- docker - Elasticsearch 保护连接
- reactjs - 如何使用打字稿在Hoc中为html元素使用Ref
- python - 从字符串列表中提取第一个选项卡之前的所有文本
- php - Prestashop 1.7:“自定义”特征值和非自定义特征值之间的技术区别?
- java - 使用 Spring Boot 按部分发送电子邮件(带分页)?
- google-bigquery - 更新计划查询配置:删除目标数据集