I have a problem with my layout. I use ViewPager tab layout in my app and I would like to use transparent action bar. I managed to prevent the elements from hiding behind action bar, but the problem is that elements sill hide behind the tabs bar. How to fix it?
xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="?android:attr/actionBarSize"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:background="#E3F6CE">
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
Use CoordinatorLayout to wrap all components and use this app:layout_behavior="#string/appbar_scrolling_view_behavior" in your RelativeLayout where xmlns:app="http://schemas.android.com/apk/res-auto"
Related
I'm working on an android app and am using a toolbar at the top of the screen and a navigation bar at the bottom of the screen. I'm using a single activity to create the top and bottom toolbars and fragments to change the content between the toolbars. However, when the contents in the fragment go beyond the size of the screen, the bottom bar disappears.
Here is my home activity xml:
<?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:id="#+id/activity_home"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.rentables.testcenter.HomeActivity">
<include
android:id="#+id/toolbar_main"
layout="#layout/toolbar_main"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<fragment android:name="com.rentables.testcenter.HomeFragment"
android:id="#+id/fragment_place"
android:layout_weight="0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="#layout/fragment_home" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="bottom">
<include
android:id="#+id/toolbar_navigate"
layout="#layout/toolbar_navigate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"/>
</LinearLayout>
</LinearLayout>
Im guessing it's because of the inner linear layout I have, but I wasn't sure how else to get the nav bar to stay static at the bottom. Any help would be awesome. Thanks
Figured it out. I just changed the whole thing to a relative layout, got rid of the inner linear layout, and instead of gravity I used alignParentBottom="true".
whenever i open my navigation drawer frame layout contents are getting shown in background i even tried setting the frame's color white
main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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"
android:id="#+id/drawer_layout"
tools:context="com.example.sumanravi.knowmycity.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/content_layout"
android:background="#color/white">
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical">
<ListView
android:layout_width="200dp"
android:layout_height="match_parent"
android:id="#+id/navList"
android:choiceMode="singleChoice">
</ListView>
</LinearLayout>
If what you want to do is to hide the contents of a layout, you can:
Hide the whole layout (setting visibility to View.GONE or View.VISIBLE)
Change the alpha (setting alpha on the layout itself)
Remove all of the layout's children (please don't use this method, it's stupidly slow)
Containing views will always have their parent's background drawn underneath them. Another fun way to hide the content is to use the drawer listener: https://developer.android.com/reference/android/support/v4/widget/DrawerLayout.DrawerListener.html#onDrawerSlide(android.view.View, float) - look for onDrawerSlide(View, float) method and (for example) change the View's alpha as you go.
Another thing you could do with FrameLayouts is to set the foreground: set forground color in framelayout in android programatically
But generally, content under navigation drawers is always (at least partially) visible. If you're trying to hide it, you're probably not following the guide.
My drawerLayout is intercepting all touch events. I need help figuring out how to click on elements below it. Here is how my drawerLayout is set up
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/frag_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
.... some code ...
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
I then reference this layout in another layout like this
<!-- elements inside of this relative layout
are unclickable because the drawer layout below
intercepts all clicks. If I place the drawer above
this view the drawer is beneath all the elements
in the relative layout, however, I am able to do
my clicks as expected. What I am doing incorrectly? -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- ... some code * the buttons here are what
I want to be clickable when drawer is closed.
I currently cannot reach them ... -->
</RelativeLayout>
<include layout="#layout/drawer" />
</FrameLayout>
I have added android:clickable="false" and android:focusable="false" in the xml on the drawer. Programmatically I logged the clicks, and it is the actual drawer with id "drawer_layout" intercepting all clicks. Making it unclickable does not work, it is still clickable. I also tried setting the visibility to INVISIBLE and GONE and these are not viable solutions either.
How can I make that drawerLayout allow clicks through it to elements beneath it? Thanks in advance!
By setting clickable and focusable to false, I think you are disabling click to the views in the layout too. Remove these options from the drawer layout.
Try setting android:clickable="true" and android:focusable="true" for the container inside the drawer layout.
I figured this out. I ended up adding my main layout to the drawer which is the reverse of what I was doing before because before I was adding the drawer to my main layout. So the change I made was
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/frag_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include layout="#layout/main_layout" />
</FrameLayout>
<RelativeLayout
.... some code ...
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
If anyone else runs into this problem it is view hierarchy conflict. You cannot have your drawer on top of elements that you want to interact it. If you have buttons or other widgets that you need to interact it you should include it to your drawer layout instead. I hope this helps someone else out there.
I want to create an activity where there's an image view and a view pager right after. I have try some stuff, but the tabs of the viewpager always appear at the top of the screen.
In order what I would like to have:
Action Bar
Image view (here the M)
Tab
Content of the tab (Fragment)
Here's the closest I have got.
Here's my code. (I'm pretty sur I overkilled it, but I was trying stuff)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/profile_image_linear_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<ImageView
android:id="#+id/profile_image_view"
android:layout_width="fill_parent"
android:layout_height="200dp" />
</LinearLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="#+id/profile_image_linear_layout">
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="match_parent"
tools:context="madduck.ioweyou.ProfileActivity" />
</FrameLayout>
</RelativeLayout>
Thanks in advance !
Use a TabLayout instead of the ActionBar tabs.
https://developer.android.com/reference/android/support/design/widget/TabLayout.html
For this to work you'd need to use the Android Toolbar (which is really just another View with some half-baked additions).
have a layout like this in your activity: (pseudo code)
<TOOLBAR>
<IMAGEVIEW>
<VIEWPAGER WITH TABS>
You'll want to declare your Theme/Styles to make sure your activity contains no action bar (since you will be replacing it with the Toolbar). Also some versions of Android used to crash if you tried to add a Toolbar when there was an ActionBar. Not sure if this was fixed.
Can someone help me know how to place a Widget above a ActionBar in android.I have read some other similar queries on stackoverflow but it mentions its not possible.Following is the screen that i am trying to create.Can some one let me know how do i place the Blue layout portion above the actionbar?Or is there some other way of achieving this?
Following is my xml file
nearby.xml
<?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:orientation="vertical"
android:background="#android:color/black"
>
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="100dp" >
</LinearLayout>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</android.support.v4.view.ViewPager>
</LinearLayout>
However i am not getting the desired layout.The header layout is visible below the actionbar.
Desired Layout:
The blue bar that you see is the action bar, using a custom view. Check out setCustomView on how you can customize the action bar.