I have an app that has been running on my deivce perfectly fine for a long time. Today I decided to test it on an older device. I have an old Glaxy S4 Mini, so I loaded it up, and an entire part of my layout was missing. The missing part is a reusable layout I made, and included it in this activity. The space where it would be is not taken up by anything, it is just left empty
This is the activity layout file. Everything that is inside of include is completely missing when the app is ran.
<?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="com.example.eddie.songsPrimirenya.SearchActivityReg">
<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/search_bar_include"
layout="#layout/search_bar"
/>
<android.support.v7.widget.RecyclerView
android:id="#+id/RecyclerViewReg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_below="#+id/search_bar_include"
android:layout_margin="3dp"/>
</RelativeLayout>
and this is the layout that I was including earlier. I think it's not showing because of some compatibility issue, but I do not know what it is.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/cardSearchReg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
card_view:cardCornerRadius="5dp"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintTop_toTopOf="parent"
card_view:layout_constraintVertical_bias="0.0">
<RelativeLayout
android:id="#+id/LayoutAll"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/LayoutSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/txtInReg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:hint="#string/search"
android:singleLine="true"
android:textColorHint="#color/textHint" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/LayoutSearchModeSelect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/LayoutSearch"
android:layout_marginStart="3dp">
<Switch
android:id="#+id/swtSearchType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="false"
android:text="#string/search_by_name"
android:textColorHighlight="#color/colorAccent"
android:textSize="16sp" />
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
Here is an image of how it is supposed to look like
and this is what it ends up looking like
make your include layout match parent,it should work fine
<?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="com.example.eddie.songsPrimirenya.SearchActivityReg">
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/search_bar_include"
layout="#layout/search_bar"
/>
<android.support.v7.widget.RecyclerView
android:id="#+id/RecyclerViewReg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_below="#+id/search_bar_include"
android:layout_margin="3dp"/>
</RelativeLayout>
Related
I've created a simple android app with webview to showcase my website, so now am trying to add FAB so users can share articles with that button. Wherever I place the code, either it crashes or just not being useful when I place inside webview because it gets scrolls, am sharing my code below, can you please help with the alignment, I want FAB to be a sticky button at the right bottom of the app.
<?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">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/swipe"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_behavior="#string/appbar_scrolling_view_behavior">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</WebView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<ProgressBar
android:id="#+id/progress"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
style="?android:attr/progressBarStyle"
/>
</RelativeLayout>
Can you please guide me with the correct way of doing it, after this I've to change JAVA file.
Try this,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="75dp"
android:orientation="horizontal"
android:elevation="6dp"
android:layout_alignParentBottom="true">
<YOUR_FAB_HERE
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginEnd="25dp"
android:visibility="visible"
app:srcCompat="#drawable/ic_file_upload_white_24dp"
tools:ignore="VectorDrawableCompat" />
</RelativeLayout>
<--- your additional layout here ----->
</RelativeLayout>
in my android app I have the following layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/news_tab"
android:clipToPadding="false">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listaNews1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:divider="#color/transparent"></ListView>
<LinearLayout
android:id="#+id/ll_news_empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/news_icon"
android:tint="#color/gray_dark"
android:scaleType="centerCrop" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nessuna news da mostrare"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/gray_dark"/>
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
And programmatically I have this code to add the empty view:
...
listaNovità = (ListView)view.findViewById(R.id.listaNews1);
listaNovità.setEmptyView(view.findViewById(R.id.ll_news_empty_view));
...
But executing the code on emulator I see an empty layout (the listview is empty and the empty view is not showing).
What is the reason and how can I fix the problem?
Thanks everyone wants to help me.
I'm trying to add the image view but when I do it has so much space between the top and bottom of the image. I'm using a bottom navigation with fragments. I would like to make the image close to the top with the space. What am I doing wrong with this layout?
Main Activity
<?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:design="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="com.example.android.gershpark.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/main_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:contentDescription="main image"
android:src="#drawable/fb_img_1497698892826" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frame_layout"
android:layout_below="#id/main_image"
/>
<View
android:id="#+id/view"
android:layout_width="match_parent"
android:layout_height="8dp"
android:background="#drawable/shadow"
android:layout_above="#+id/bot_nav">
</View>
<android.support.design.widget.BottomNavigationView
android:id="#+id/bot_nav"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
android:background="#android:color/holo_blue_light"
design:itemIconTint='#f8f8f8'
design:menu='#menu/bot_menu'
/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
Home Fragment
<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="com.example.android.gershpark.HomeFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Home"/>
</FrameLayout>
Looks like by adding the following it removed the spacing that was there.
android:adjustViewBounds="true"
i have an app that uses tabs to show different content..... there is an admob banner below the tabs that should never move..... it should be locked to the bottom of the screen...........
most of the content is shown using activity_main.xml which includes content_main.xml using and i have never had a problem with the layout before..... everything fit fine.....
here is what the layout is SUPPOSE to look like....
i recently added a new tab and java file called bpm counter....
the bpm counter tab has its own layout and doesn't use activity_main.xml or the content_main.xml instead it uses its own activity_main2.xml and everything is sort of working but here is the problem....
when i open the app everything looks normal like it always has with the banner at the bottom of the page.... however when i click the bpm counter tab the admob banner moves down and goes half way of the screen....... then when i try to go back to any other tab the banner moves wayyy up and i get a white space below the admob banner
you can see the problem of the banner moving down when i visit the bpm tab here
and then when i try to go back to the home page or any other tab the banner moves way up... as you can see in the photo below
i have tried changing match_parent and fill_parent and have tried a lot of tweak in the layout but i can not figure out what i am doing wrong and i am about to bang my head off a wall.... any help would be wonderful and appreciated!
here are my .xml layout files
activity_main.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="com.raptools.app.raptools.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
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"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
here is my content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
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:screenOrientation="portrait"
android:background="#000000"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.raptools.app.raptools.MainActivity"
tools:showIn="#layout/activity_main">
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="0dp"
android:layout_height="0dp"
android:screenOrientation="portrait"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-4075500144464557/8371434413"/>
<WebView
android:id="#+id/activity_main_webview"
android:layout_width="match_parent"
android:screenOrientation="portrait"
android:layout_height="match_parent"
android:layout_above="#id/adView" />
<ImageView
android:id="#+id/homepageimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:src="#drawable/homepageimage"
android:layout_above="#id/adView"
/>
<ImageView
android:id="#+id/comingimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:src="#drawable/comingsoon"
android:layout_above="#id/adView" />
</RelativeLayout>
those two layout files were working fine until i tried to add the new bpm counter tab......
here is the activity_main2.xml that is used for the bpm counter java
<?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="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true"
tools:context="com.raptools.app.raptools.MainActivity"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
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:textColor="#color/ColorRemoveAds"
app:itemIconTint="#color/ColorRemoveAds"
app:popupTheme="#style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:id="#+id/appView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#drawable/transitioning_background"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".BpmCounter">
<TextView
android:id="#+id/bpmLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="#string/bpm"
android:textColor="#color/textColor"
android:textSize="40sp"/>
<TextView
android:id="#+id/bpmTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/bpmLabelTextView"
android:layout_centerHorizontal="true"
android:text="#string/initial_bpm_value"
android:textColor="#color/textColor"
android:textSize="70sp"/>
<Button
android:id="#+id/tapButtonView"
android:layout_width="100dp"
android:layout_height="80dp"
android:layout_above="#+id/instructionalLabelTextView"
android:layout_centerHorizontal="true"
android:layout_marginBottom="32dp"
android:background="#drawable/round_button"
android:text="#string/tap"
android:textColor="#color/textColor"
android:textSize="30sp"/>
<TextView
android:id="#+id/instructionalLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="28dp"
android:text="#string/reset_instructions"
android:textColor="#color/textColor"/>
</RelativeLayout>
</LinearLayout>
i hope i have explained in enough detail and any help would be amazing!
i ended up staring at the three codes i posted above for a long time and decided to copy the frame from activity_main.xml pasted it in the activity_main2.xml and removed the linear layout and made sure to include android.support.design.widget.CoordinatorLayout and i managed to get it working!
here is the working code incase anyone has this problem ever
activity_main2.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="com.raptools.app.raptools.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
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"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:id="#+id/appView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:screenOrientation="portrait"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_weight="1"
android:background="#drawable/transitioning_background"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".BpmCounter">
<TextView
android:id="#+id/bpmLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="#string/bpm"
android:textColor="#color/textColor"
android:textSize="40sp"/>
<TextView
android:id="#+id/bpmTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/bpmLabelTextView"
android:layout_centerHorizontal="true"
android:text="#string/initial_bpm_value"
android:textColor="#color/textColor"
android:textSize="70sp"/>
<Button
android:id="#+id/tapButtonView"
android:layout_width="100dp"
android:layout_height="80dp"
android:layout_above="#+id/instructionalLabelTextView"
android:layout_centerHorizontal="true"
android:layout_marginBottom="32dp"
android:background="#drawable/round_button"
android:text="#string/tap"
android:textColor="#color/textColor"
android:textSize="30sp"/>
<TextView
android:id="#+id/instructionalLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="28dp"
android:text="#string/reset_instructions"
android:textColor="#color/textColor"/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
I have a activity_pic.xml layout which includes content_pic.xml to define the layout of my app. The activity_pic.xml is below:
<?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="com.example.olivia.myapplication.PicActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
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"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_pic" />
</android.support.design.widget.CoordinatorLayout>
content_pic.xml is
<?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="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="#+id/pick_image_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_text"/>
<ImageView
android:id="#+id/image_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>
When I include the line <include layout="#layout/content_pic" /> within the AppBarLayout (that is, I move it up two lines) the button appears, and all the functionality of the button works. However when I put it after that, the button does not appear, and all I can see is the 'App Bar' bit of the layout.
Ok so the picture below shows how I would like it to look (and how the design view shows content_pic.xml)
And here is what it actually looks like
However, when I put the <include layout="#layout/content_pic" /> into the AppBarLayout I can see the button, as shown in the image below.
I have tried taking the content of content_pic.xml and including it directly instead of using the include statement, this still does not appear.
I've run out of ideas here - can anyone suggest what might be going wrong?
AppBarLayout works good if you us NestedScrollView or RecyclerView
so I suggest you change your content_pic.xml TO.
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="#+id/pick_image_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_text"/>
<ImageView
android:id="#+id/image_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>
I hope this will Help.
EDIT
You Just need to Change your content_pic.xml to this
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<!-- Importent -->
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="#+id/pick_image_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello" />
<ImageView
android:id="#+id/image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>