Reputation: 47
When the application is launched, my layout is displayed for a very short second and then disappears. As a beginner in Kotlin, I don't understand why it produces this result.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="univ.master.kotlin.weather.city.CityFragment">
<fragment
android:id="@+id/city_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="univ.master.kotlin.weather.city.CityFragment"/>
</LinearLayout>
Upvotes: 0
Views: 661
Reputation: 399
I had the same issue, it appears that reusing a view ID which is assigned to a different view type in another layout causes the view layout to disappear in the preview.
Layout 1 has a button with id = "progress_bar"
<Button
android:id="@+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
..... />
Layout 2 has a ProgressBar with id = "progress_bar"
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="30dp"
android:layout_height="30dp"
....."/>
The solution is to make sure any reused view IDs are not assigned to a different view type in another layout.
Upvotes: 0
Reputation: 171
Thank you for sharing your xml and java code. If you tried everything and still layout is not appring it is just because of android studio is not able to catch you .xml code not to worry.
You can Select all xml code ctrl+A>ctrl+X>ctrl+V Don't ask me how.
I don't even know how but it works for me. You can also try this because this is the android studio universal rule
Rebuild project or Clear catch and restart
Hope it helps
Upvotes: 1
Reputation: 101
It's just a message from the preview window telling you that it can't show a preview for the fragment tag due to not knowing what kind of fragment you'll insert. When you run your actual app, the fragment will render fine.
try to add :
tools:layout="@android:layout/YOUR_LAYOT"
<fragment
android:id="@+id/city_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@android:layout/YOUR_LAYOT"
android:name="univ.master.kotlin.weather.city.CityFragment"/>
Upvotes: 1