tabhost or layout is pushing admob banner below screen - android

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>

Related

Included layout missing on Android API 21

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>

Not able to set Admob Ads at bottom in ConstraintLayout

I just set my webview in ConstraintLayout. I am not able to show Banner at bottom of activity. It always overlays the action bar. All i want to show id first Action bar then webview then at bottom banner ads.
Below image show the current layout:
Here is my activity_browser.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"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:fitsSystemWindows="true"
tools:context=".webBrowser.BrowserActivity">
<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="?android:attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include
android:id="#+id/include"
layout="#layout/content_browser_full" />
<ProgressBar
android:id="#+id/progressBar"
style="#style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-7dp"
android:indeterminate="true"
android:visibility="gone"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/banner_ads"/>
</android.support.design.widget.CoordinatorLayout>
Here is content_browser_full.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fadeScrollbars="false"
android:scrollbarFadeDuration="0"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="52dp"/>
</android.support.v4.widget.NestedScrollView>
May be you already solve but some other will help this.
You need to add bellow code
ads:layout_constraintBottom_toBottomOf="parent"
full code:
<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
android:layout_gravity="bottom"
ads:layout_constraintBottom_toBottomOf="parent"
ads:adUnitId="#string/banner_home_footer">
</com.google.android.gms.ads.AdView>
I can not see ConstraintLayout but only a CoordinatorLayout The easy way is to add this line:
android:layout_gravity="bottom"
to your AdView. Bear in mind this will also be on top of your browser(WebView) but a the bottom of the Screen. If it fits your need use it, else elaborate what you want.

RecyclerView pull up loading data response delay in CoordinatorLayout AppBarLayout

My xml layout is shown below:
<?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:fresco="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/root_literature_fm"
android:layout_width="match_parent"
android:layout_height="match_parent">
<net.cnki.tCloud.view.widget.TitleBar
android:id="#id/base_titlebar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.design.widget.CoordinatorLayout
android:id="#+id/root_literature_fm_literature_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/base_titlebar"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
app:layout_scrollFlags="scroll|enterAlways|snap">
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/sdv_magazine_cover"
android:layout_width="90dp"
android:layout_height="120dp"
android:padding="13dp"
fresco:actualImageScaleType="centerCrop"
fresco:placeholderImage="#mipmap/side_surface"
fresco:placeholderImageScaleType="centerCrop"/>
<TextView
android:id="#+id/tv_magazine_name"
style="#style/TextItemMagazineTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/sdv_magazine_cover"
android:ellipsize="end"
android:maxLines="1"
android:paddingBottom="55dp"
tools:text="title"/>
<TextView
android:id="#+id/tv_magazine_date"
style="#style/TextItemMagazineSubtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/sdv_magazine_cover"
android:ellipsize="end"
android:paddingTop="55dp"
tools:text="1922"/>
</RelativeLayout>
<include layout="#layout/layout_literature_filter"/>
</android.support.design.widget.AppBarLayout>
<com.jcodecraeer.xrecyclerview.XRecyclerView
android:id="#+id/xrv_literature"
android:name="net.cnki.tCloud.view.fragment.LiteratureFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="false"
app:layoutManager="LinearLayoutManager"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
<ViewStub
android:id="#+id/vs_no_literature"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/base_titlebar"
android:layout="#layout/layout_literature_unbind"/>
My problem is delayed response when i slide up the screen to load data. The link is a video of the issue.https://www.youtube.com/watch?v=VaaAl-omBiY
I think this problem is setting behavior.This touch event is a delay passed to RecyclerView.
Please help me this problem has been bothering me for a long time.
this is a bug of supportlibrary,and not fixed in 27.1.0
https://issuetracker.google.com/issues/66996774
try https://gist.github.com/chrisbanes/8391b5adb9ee42180893300850ed02f2, it works

LinearLayout isn't shown when included in content layout

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>

Landscape imageview overlap toolbar and statusbar

I have an imageview which is displayed in center of the screen. In portrait mode it displays fine but when i rotate screen in horizontal mode then imageview is opelapping my toolbar and status bar like in screenshot attached below. I tried couple of settings but it didn't change anything. I tired below toolbar option but it will attach imagview after toolbar but i need to display imageview in center.So I need a help to fix this laypout.Here is my layout xml code.
Imageview layout:
<RelativeLayout 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=".DetailActivity"
>
<include android:id="#+id/toolbar"
layout="#layout/toolbar"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:scaleType="centerInside"
android:adjustViewBounds="true"
android:transitionName="photo_hero"
android:id="#+id/image"
/>
</RelativeLayout>
toobal layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark" >
</android.support.v7.widget.Toolbar>
screenshot:
http://s9.postimg.org/6lyxbaq27/landscape_problem.png
http://s9.postimg.org/n8ghkdizz/landscape_problem_2.png
Put this:
android:layout_below="#+id/toolbar"
inside of your <ImageView> tag.
It should look like:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
android:layout_centerInParent="true"
android:scaleType="centerInside"
android:adjustViewBounds="true"
android:transitionName="photo_hero"
android:id="#+id/image"
/>
Instead of relative layout try to use Frame Layout like:-
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/main_parent_view"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:scaleType="centerInside"
android:adjustViewBounds="true"
android:transitionName="photo_hero"
android:id="#+id/image"
/>
</LinearLayout>
<include layout="#layout/toolbar"/>
As Viktor suggested. I used linearlayout with orientation vertical and with few parameter changes in my imageview.Here is the final code:
<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"
tools:context=".DetailActivity"
android:orientation="vertical"
>
<include android:id="#+id/toolbar"
layout="#layout/toolbar"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:id="#+id/image"
android:layout_gravity="center_horizontal"
/>
</LinearLayout>

Categories

Resources