I have a problem with skipping frames, on a real device which is around 90-110 frames, but on the emulator it's only 20-30.
I am having that problem because I have 5 fragments inside an activity, and every fragment has 15-30 buttons which are LinearLayouts, because I needed to have two pictures and TextView in one Button and that seemed a way to go.
That's the reason it is skipping frames and I need to wait a few seconds before it opens the activity.
That's not looking good and since I can't have less data in Fragments, I have decided to create loading animation.
But the problem is, whenever I create it ,following various tutorials on YouTube or StackOverflow, the loading animation appears only when the activity opens, and there's no use of it then.
Does anyone know the solution?
activity xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:fitsSystemWindows="true"
tools:context="hr.app.liftme.liftmehr.Vjezbe">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
android:elevation="0dp"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.AppBarOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_vjezbe" />
</android.support.design.widget.CoordinatorLayout>
content xml
<?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"
android:elevation="0dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="hr.app.liftme.liftmehr.Vjezbe"
tools:showIn="#layout/activity_vjezbe"
android:id="#+id/loadingPanel">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="Vježbe"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
app:tabMode="scrollable"
app:tabGravity="fill"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/viewPager"
android:background="#ffffff">
</android.support.v4.view.ViewPager>
</android.support.design.widget.AppBarLayout>
</LinearLayout>
You can take a look at the Branded Launch Theme which has been added in the new Material Design Libraries of Android, for preventing cold starts of applications and can replace the loading animations. There's a really good article here by Antonio Leiva.
You can insert a layout in your XML (for example a RelativeLayout with background color and a spinner) that takes all the screen size. And when you have finished loading the fragments, set that layout's visibility to Gone.
Related
Have being trying to build this layout but I don't while its not running yet
'''
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#90A4AE"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp">
</android.support.v7.widget.Toolbar>
'''
You forgot to close the Linear Layout !
Use the code below.
Always remember that you have to close the tag either by using ".../>" at end or "</..>" after adding widgets inside it...
Please note that I also replaced the old support library tablayout with a tablayout from material library
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#90A4AE"
android:orientation="vertical">
<com.google.android.material.tabs.TabLayout
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp">
</com.google.android.material.tabs.TabLayout>
</LinearLayout>
I don't know why fragment is not working. I am creating bottom navigation. My code is here. Please solve my problem.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/draw">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bot_nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/bottom_navigation_menu" />
This is the fragment part. Please solve my problem. The app is not working.
This is the fragment part. Please solve my problem. The app is not working.
<fragment
android:id="#+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="#id/bot_nav_view"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="#navigation/bot_navigation"
/>
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="false"
app:popupTheme="#style/AppTheme.AppBarOverlay." />
</com.google.android.material.appbar.AppBarLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
This is the bot_navigation.xml code. Please check it also.
<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="#+id/bot_navigation"
tools:ignore="UnusedNavigation">
<fragment
android:id="#+id/navigation_feed"
android:name="com.example.reducestress.ui.feed.feed"
android:label="#string/title_feed"
tools:layout="#layout/feed_fragment" />
<fragment
android:id="#+id/navigation_diary"
android:name="com.example.reducestress.ui.diary.diary"
android:label="#string/title_diary"
tools:layout="#layout/diary_fragment" />
<fragment
android:id="#+id/navigation_profile"
android:name="com.example.reducestress.ui.profile.profile"
android:label="#string/title_profile"
tools:layout="#layout/profile_fragment" />
</navigation>
With the new JetPack Navigation, you need to add the fragments you want to show to your NavGraph. You can find your NavGraph under the navigation directory from the res directory. In your case, your NavGraph is bot_navigation.xml.
If you don't see the fragment you want to show, once you are inside your NavGraph, there will be this icon
Click it and you will see a list of the available fragments and activities. Just click the one you want.
If your fragments are already placed, make sure the id's match with the id's in your bottom_navigation_menu.xml. Also, make sure that in your host activity you are setting up the Navigation with the right NavController and with the right BottomNavigationView.
Let me know if it helped.
try to change <fragment to <FrameLayout its work for me when i use FrameLayout
and turn black when i change it to <fragment
You forgot in navigation app: startDestination = "# id / navigation_feed instead of navigation_feed put the fragment that should be launched first and i think you should remove unusedNavigation
The code that should look like:
<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="#+id/bot_navigation"
app:startDestination="#id/navigation_feed">
...
</navigation>
So I will have my main-activity layout file below so you can understand what is happening
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".MainActivity">
<include
android:id="#+id/toolbar"
layout="#menu/toolbar"/>
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottom_nav">
</FrameLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:menu="#menu/bottom_navigation"
app:itemIconTint="#android:color/white"
android:background="#39b54a"
app:labelVisibilityMode="unlabeled">
</com.google.android.material.bottomnavigation.BottomNavigationView>
</RelativeLayout>
The problem with this layout is that the toolbar on the top and the bottom navigation bar cover content from my fragments. Also one of my fragments has got a recyclerview with many items and I can´t scroll down for some reason ? Is there a way to make the fragments fit exactly between the toolbar and bottomnavigation like resizing itself to fit into that area without cutting content and still make it scrollable ?
Do it like this ...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".MainActivity">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar_layout"/> <!--include your layout file here -->
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_below="#id/toolbar"
android:layout_height="match_parent"
android:layout_above="#+id/bottom_nav">
</FrameLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:menu="#menu/bottom_nav_menu"
app:itemIconTint="#android:color/white"
android:background="#39b54a"
app:labelVisibilityMode="unlabeled">
</com.google.android.material.bottomnavigation.BottomNavigationView>
</RelativeLayout>
And by the way, you are supposed to set a layout resource file into the toolbar layout while including but you are passing the menu resource file. Change that also accordingly...
I am sorry if this question is duplicated.
I am new to android programming, and I am building application for public transport, and i have done so far this: getting the directions form google, parsing json data, and display on the map.
Now I want to display routes in list view with icons bus and train.
A have seen that can be done via Collapsing toolbar and recycle view, but every tutorial that I have seen i am getting error is this because is Android studio 3.0.
This is picture i want to display
In this list view I want to add pictures like if is tram transport than tram icon of bus and if it is combination of multiple tram or bus lines to display that. Can anybody help me or give me advice?
Android provide CollapsingToolbarLayout while scrolling it will collapse toolbar in recycle view. Use this :
android.support.design.widget.CollapsingToolbarLayout
for more read CollapsingToolbarLayout
Happy coding!!
Try this code. It worked for me just simply put imageview in collpasing layout and change it with your options.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:background="#color/white"
android:orientation="vertical"
android:animateLayoutChanges="true"
tools:context="com.example.intel.magitor.My_Creation_Activity"
>
<android.support.design.widget.AppBarLayout
android:background="#fff"
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="400dp"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|snap|exitUntilCollapsed">
<!--<android.support.v7.widget.Toolbar-->
<!--android:id="#+id/toolbar"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="?attr/actionBarSize"-->
<!--app:layout_collapseMode="pin"-->
<!--app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />-->
<!-- use this v7.wdiget.toolbar if you want to display title collpasing layout-->
<!-- put here your image you want to collpase while scrolling-->
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/video_list"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
>
</android.support.v7.widget.RecyclerView>
</android.support.design.widget.CoordinatorLayout>
I have been following these probably outdated instructions to insert (test) ads to my android project. After I have recompiled the project on a virtual Nexus 5 phone, the app works, but no add-banner is shown.
Maybe there is a problem with the layout file, as my layout file does not look like the example layout file. Here are the relevant parts of my layout file to include the ad-banner:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity" >
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"/>
</android.support.design.widget.AppBarLayout>
<LinearLayout
...
...
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
Is the problem related to the layout? How else to figure out why the ad banner is not shown?
In a discussion with the OP, it turned out that the CoordinatorLayout and the AdView were both inside a LinearLayout, and the CoordinatorLayout was pushing the AdView off of the screen because its height was "match_parent"
By changing the CoordinatorLayout height to 0dp, and weight to 1, it will grow to fill the remaining space above the AdView instead of taking the entire screen.
android:layout_height="0dp"
android:layout_weight="1"
I think you should be using:
xmlns:ads="http://schemas.android.com/apk/res-auto"
instead of:
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"