I am trying to add a Navigation Drawer inside my app. Here's the code:
<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"
tools:context="com.example.abcxyz.properprojectdb.MyDrawerActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>
<ListView
android:layout_width="240dp"
android:layout_height="match_parent"
android:id="#+id/listView"
android:entries="#array/planets"></ListView>
</DrawerLayout>
I am unable to add the attribute android:layout_gravity for ListView. I don't know why it is not available for use (intellisense works perfectly, but it won't show layout_gravity)
My app crashes when I run it, but if I replace DrawerLayout with LinearLayout, the app doesn't crash.
I am guessing that it is because I have not added the attribute android:layout_gravity for ListView.
Here's a snapshot to show that layout_gravity doe not appear in intellisense either
I had the same issue and I wasted maybe 2 hours to find a solution. I tried restarting the IDE, invalidating, downgrading from 23 to 22, nothing worked.
Eventually, I HARD TYPEd it and it became available after I finished typing
android:layout_gravity=
(Worth mentioning I was on AS 2.1 ... maybe there was a weird bug)
Replace:
DrawerLayout
with
android.support.v4.widget.DrawerLayout
and add following line to your build.gradle:
compile "com.android.support:support-v4:22.0.0"
UPDATE
DrawerLayout should consist of 2 views and it seems that you cannot set layout_gravity to the view which represents drawer itself. You can always wrap your ListView in other layout and then set layout_gravity on your ListView.
Every things seem to be no problem. You can put android:layout_gravity="start" or android:layout_gravity="end" in ListView
UPDATE
I saw my bad. #questioner was right. Your must change DrawerLayout to android.support.v4.widget.DrawerLayout
Related
I saw that this statement used inside an xml layout will automate animations for you. I want to add this to my app, but when I put it in the layout I want
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/arrow_background"
android:layout_marginTop="7dp"
android:layout_marginBottom="7dp"
android:padding="10dp"
android:animateLayoutChanges="true"
android:visibility="visible"
android:id="#+id/format_help">
And then I change the visibility to gone
view.findViewById(R.id.format_help).setVisibility(View.GONE);
It only just instantly goes away. The information I saw about this was from a few years ago so does anyone know if this is still supposed to work or how to get it to work?
EDIT: Also I added this statement everywhere and it still does not working. If it matters this is inside a fragment/dialog
It works for views inside container which has the property android:animateLayoutChanges="true". If a Linear layout having the above property, whenever a new view added or removed from that container the effect is visible. The animation effect will not be visible to the container itself when container is added or removed. For more information check the below link.usage of animateLayoutChanges
I am going on with the scroll action in my Android Device if i scroll any thing in the device after it reaches the end point in top and bottom if even we scroll it shows some colours for different device eg:(samsung it shows blue light).
Here i attached a screenshot below:
How can we remove it or if no chance can we change the color
Usually we will use ScrollView,Listview etc to scroll the view should go on with XML or progrmatically.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fillViewport="true"
android:overScrollMode="never"
android:scrollingCache="false"
android:fadingEdge="none" >
TRIED
android:cacheColorHint="#00000000"
android:scrollingCache="false"
list.setCacheColorHint(Color.TRANSPARENT);
android:fadingEdge="none"
listView.setVerticalFadingEdgeEnabled(false);
android:overScrollMode="never"
But no change can any one help me to fix this issue.
this effect is named overscroll
listView.setOverscrollFooter(new ColorDrawable(Color.RED));
listView.setOverscrollHeader(new ColorDrawable(Color.RED));
be awared that some devices ignores this params, example here
I don't know how to completely disable the overflow in the ScrollView, but I have come across a library that you can use so as to change your overflow color.
LINK:https://github.com/AndroidAlliance/EdgeEffectOverride
Here is the solution which helped me to solve
Custom overscroll glow/edge color for ListView?
for the user Menny
referred link:http://evendanan.net/android/branding/2013/12/09/branding-edge-effect/
Hope this help's you
Whenever I have Views inside a ViewGroup inside a android.support.v4.widget.DrawerLayout, Eclipse's autocomplete starts working weird. It doesn't display most of the properties
Example with DrawerLayout -> LinearLayout -> ImageView:
In the previous screenshot, you can see that I typed "android:scale..." and the IDE's intellisense isn't showing me the ImageView's android:scaleType
If I use Eclipse's Properties window for the ImageView, I can see that it is only displaying the basic properties for "View" (and not for ImageView...):
Now if the ImageView is not a descendant of the DrawerLayout and I put it somewhere else, the autocomplete works properly:
I've seen related questions such as:
Autocomplete does not work in XML files in particular hierarchy
Content Assist doesn't work in xml with support library
but they have been dead with no answers for quite a while...
Content assist doesn't work for Views (be it TextViews, EditText, Buttons...) that I add inside the DrawerLayout. It only suggests the 'basic' properties.
Does anybody know why this happens or how to fix this?
Sample layout:
<?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" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/some_image" />
</LinearLayout>
<RelativeLayout
android:id="#+id/drawer_view"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start" >
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
Just to give some closure to this 5 months-old question, I'll quote and link to Atul O Holic's answer. Thanks to Dileep Perla for pointing me there.
When using support package Widgets this is a common scenario (a weird
one too).
Here you using, android.support.v4.widget.DrawerLayout and hence the
issue. Happened with me a lot of time.
You can also try couple of options mentioned here.
I've found that using the tag can be handy in this case. Just put your layout that is inside the drawer in a separate layout file and then include it inside the drawer layout.
I'd like to create an extra-information view similar to that of the Google Drive app (below) on a tablet. When the info button is clicked, this view slides in from the rightcontaining a layout. Another example would be the Google+ app with its notifications slide-out panel:. The SlidingLayer by 6Wunderkinder almost works, but doesn't fade a semi-black background over the views behind the "drawer" and I haven't found another library that does this.
If anybody has any suggestions/solutions please let me know!
Also, I've already looked at this question and none of the answers suggested there are correct either.
For posterity, here's the answer to this question. As Steve Benett's suggestion led me to discover, the correct way to do this is to use two DrawerLayouts, nested within each other like so:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_navigation_bar"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_sidebar"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/fragment_main_content"
android:name="MainContentFragment"
android:layout_height="match_parent"
android:layout_width="match_parent" />
<fragment
android:id="#+id/fragment_sidebar"
android:name="SidebarFragment"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="end" />
</android.support.v4.widget.DrawerLayout>
<fragment
android:id="#+id/fragment_navigation_bar"
android:name="NavigationFragment"
android:layout_height="match_parent"
android:layout_width="300dp"
android:layout_gravity="start" />
</android.support.v4.widget.DrawerLayout>
The innermost DrawerLayout contains the main content of the Activity, whether it be a fragment or some other layout components. fragment_sidebar is the fragment that will be swiped out from the right. Then, on the top-level DrawerLayout you have the fragment_nagivation_bar which houses the left Drawer's ListView or whatever.
Then, in the Activity Java code you have:
mDrawerLayoutLeft= (DrawerLayout) findViewById(R.id.drawer_navigation_bar);
mDrawerLayoutRight = (DrawerLayout) findViewById(R.id.drawer_sidebar);
mDrawerLayoutLeft.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
mDrawerLayoutRight.setDrawerShadow(R.drawable.sidebar_shadow, GravityCompat.END);
An optional addition (but recommended, for consistency of UX) is to hide the other Drawer when one is opened, so your screen doesn't consist solely of Drawers.
I hope this has helped somebody!
This is the DrawerLayout. Have a look at the design guide, which illustrates the behavior well.
If you want to use / customize the "semi-black background" use DrawerLayout.setDrawerShadow() with a drawable. Google hands out a set of drawables here. Download the ActionBar Icon Pack and look for the drawable_shadow.9.png.
If you want that the menu appears from the right, set android:layout_gravity="end" as a property in the second child of the layout.
My Android app has a main WebView (HTML loaded from a local resource) which I want to use the entire width of the screen and be able to make (vertically) scrollable. So I've wrapped the WebView in a ScrollView in my layout XML, but no matter what I do I can't seem to be able to remove the scroll bar track from the right side of the scroll view. Even worse, I can't seem to be able to change the background colour of the scroll bar track.
The track takes up about 10dp's or so, which is creating problems for the HTML in the WebView. I'd like the scroll bar to appear on top of the web view (iPhone style, if you know what I mean). Now, you could say "why don't you change your HTML to be 10px thinner?", which is my fallback solution, but I'd much rather not have to.
Here's the relevant snippet of layout XML, you'll see I've tried every android:etc attribute I could find:
<ScrollView
android:id="#+id/deal_web_view_holder"
android:layout_below="#id/clock_bar_holder"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="false"
android:fadingEdge="none"
android:background="#02a7e9"
android:scrollbars="none"
android:scrollbarSize="0dp"
android:paddingRight="0dp"
android:scrollbarAlwaysDrawVerticalTrack="false"
android:scrollbarStyle="insideOverlay"
android:scrollbarTrackVertical="#drawable/scrollbar_track_vertical" >
<WebView
android:id="#+id/deal_web_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</ScrollView>
I'm targeting platform 2.1 / API lvl 7, really just dealing with normal size displays, mdp, hdp and xhdp.
To remove a scrollbar from a view (and its subclass) via xml:
android:scrollbars="none"
http://developer.android.com/reference/android/view/View.html#attr_android:scrollbars
try this is your activity onCreate:
ScrollView sView = (ScrollView)findViewById(R.id.deal_web_view_holder);
// Hide the Scollbar
sView.setVerticalScrollBarEnabled(false);
sView.setHorizontalScrollBarEnabled(false);
http://developer.android.com/reference/android/view/View.html#setVerticalScrollBarEnabled%28boolean%29
I'm a little confused why you are putting a WebView into a ScrollView in the first place. A WebView has it's own built-in scrolling system.
Regarding your actual question, if you want the Scrollbar to show up on top, you can use
view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY) or
android:scrollbarStyle="insideOverlay"
Solved my problem by adding this to my ListView:
android:scrollbars="none"
These solutions Failed in my case with Relative Layout and If KeyBoard is Open
android:scrollbars="none" &
android:scrollbarStyle="insideOverlay" also not working.
toolbar is gone, my done button is gone.
This one is Working for me
myScrollView.setVerticalScrollBarEnabled(false);
By using below, solved the problem
android:scrollbarThumbVertical="#null"