Jul*_*ñas 26 android android-studio
为了能够看到预览Android Studio中的布局时,一个片段内部的某一观点的内容,它是可以做到这样:
<MainLayoutView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<fragment
...
tools:layout="@layout/my_fragment_view"/>
</MainLayoutView>
Run Code Online (Sandbox Code Playgroud)
但是,如果您从 切换fragment到androidx.fragment.app.FragmentContainerView,这个方便的工具将停止工作,片段在预览屏幕上只会显示为空白。
FragmentContainerView在 Android Studio 的布局中预览内容时,有没有办法在 a 中显示内容?
小智 1
正如tir38 的评论 中所述,此问题已在 Android Studio 的更高版本中修复,您现在可以在 FragmentContainerView 中使用 tools:layout 属性。在使用导航组件的情况下,如果您为使用tools:layout属性的导航图定义了startDestination ,这将自动反映在您的FragmentContainerView中
<androidx.fragment.app.FragmentContainerView
...
app:navGraph="@navigation/nav_graph"/>
<navigation
...
app:startDestination="@id/someFragment">
<fragment
...
android:id="@+id/someFragment"
tools:layout="@layout/fragment_splash"/>
</navigation>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1355 次 |
| 最近记录: |