繁体   English   中英

在android studio中设计时不显示片段的结构。只显示阴影。如何在设计时获取原始片段?

[英]Structure of fragment isn't shown during design in android studio.Only the shade is shown.How to get the original fragment during design?

在设计主活动时,我尝试添加两个片段。但是在activity_main的设计选项卡中没有显示片段的原始结构,而是为每个片段显示了阴影区域。如何在设计过程中获得片段的原始结构? 在此处输入图片说明

在您的 activity_main.xml 中,确保您的每个片段标签都指定:

  • android:name带有片段路径
  • tools:layout与片段的布局

如果您使用包含标签,那么您需要在片段中使用类似tools:showIn=".MainActivity" ( docs ) 的内容。

下面是一个例子:

活动_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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM