[英]Structure of fragment isn't shown during design in android studio.Only the shade is shown.How to get the original fragment during design?
While designing the main activity I tried to add two fragments.But the original structure of the fragment is not shown in design tab of activity_main, instead shaded regions are shown for each fragment.How to get original structure of fragments during design?在设计主活动时,我尝试添加两个片段。但是在activity_main的设计选项卡中没有显示片段的原始结构,而是为每个片段显示了阴影区域。如何在设计过程中获得片段的原始结构? enter image description here
在此处输入图片说明
In your activity_main.xml make sure each of your fragment tags specify:在您的 activity_main.xml 中,确保您的每个片段标签都指定:
android:name
with a path to your fragment android:name
带有片段路径tools:layout
with the fragment's layout tools:layout
与片段的布局If you're using an include tag then you'll need to use something like tools:showIn=".MainActivity"
( docs ) in your fragments.如果您使用包含标签,那么您需要在片段中使用类似
tools:showIn=".MainActivity"
( docs ) 的内容。
Here's an example:下面是一个例子:
<?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>
<?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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.