I am unable to understand why white color is showing in the bottom of layout.
I am using view pager containing various pages.Layout contain layout background image and two text view. Problem is that white color is showing on some pages.
My Layout
<Relative Layout
android:id="#+id/layouts"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Scroll View
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<Linear Layout
android:id="#+id/images"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<Text View
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Text View
android:id="#+id/footer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:layout_gravity="center_horizontal"
/>
</Linear Layout>
</Scroll View>
</Relative Layout>
XML for view pager Declaration
<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" >
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mypager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView
android:id="#+id/drawer_list"
android:layout_width="260dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="#FFCC00"
android:dividerHeight="1dp" />
</android.support.v4.widget.DrawerLayout>
Set the ScrollView's fillViewPort attribute to true to make it fill all vertical space on screen in case the scroll view content itself doesn't use it all.
It is probably the scroll view height being set to wrap content.
So if the content is smaller than the screen height the scroll View is too, leaving a gap at the bottom of the screen.
Related
How do I get my main layout to simply line up directly underneath my DrawerLayout? My main layout is listed below and is mainly made up of listviews. Right now everything is overlapping. So the below first shows my DrawerLayout. After closing of DrawerLayout my main activity is listed.
<android.support.v4.widget.DrawerLayout
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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
</LinearLayout>
<FrameLayout
android:id="#+id/container_body"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
<fragment
android:id="#+id/fragment_navigation_drawer"
android:name=“com.example.my.app.FragmentDrawer"
android:layout_width="#dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout="#layout/fragment_navigation_drawer"
tools:layout="#layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent”
android:orientation="vertical">
<TextView
android:id="#+id/txt_empty_list_cars"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="4dp"
android:gravity="center"
android:text="#string/view1"
android:textAppearance="?android:attr/textAppearance"
android:textColor="#android:color/darker_gray"
android:visibility="gone" />
<ListView
android:id="#+id/list_cars"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_header"
android:layout_margin="4dp"
android:divider="#android:drawable/divider_horizontal_bright"
android:dividerHeight="0.5dp"
android:listSelector="#android:drawable/list_selector_background" />
So, your problem is drawer layout overlapping the linear layout below. Use
android: layout_below="#id/drawer_layout"
In your linear layout. That will linearly arrange both layouts.
I dont know if your are looking for a sliding panel like the new gmail app
but if yes you can refer yourself Sliding Pane Layout and this very awesome tutorial.
hope it helps, happy codings.
In order to use the DrawerLayout correctly, it has to be the only root / parent view of your entire layout.
<android.support.v4.widget.DrawerLayout>
/*other nested child views */
<fragment
android:id="#+id/fragment_navigation_drawer"
...
/>
</android.support.v4.widget.DrawerLayout>
Also, to prevent the over lapping, ensure that you have two direct child views as per design guideline at
https://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html
"To use a DrawerLayout, position your primary content view as the first child with a width and height of match_parent . Add drawers as child views after the main content view and set the
layout_gravity appropriately."
I have a view layout containing a ListView and a Button:
<?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:background="#5434"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:layout_weight="1.0"
android:id="#+id/itemlistView" tools:ignore="ObsoleteLayoutParam"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
tools:ignore="ObsoleteLayoutParam">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/button"
android:text="#string/new_item"
android:id="#+id/listview_addDebtButton"
android:layout_gravity="center_horizontal"
android:layout_weight="1.0"
tools:ignore="ObsoleteLayoutParam"/>
</LinearLayout>
but now i want to add a Navigation Drawer. Using the sample code from google developers. But am not sure how to do this since the sample code contains an empty content view:
<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">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
The drawer is given a fixed width in dp and extends the full height of
the container. A solid background is used for contrast
with the content view. -->
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
I however proceeded to try with this as my new layout:
<?xml version="1.0" encoding="utf-8"?>
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<ListView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:id="#+id/itemlistView" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/button"
android:text="#string/new_item"
android:id="#+id/listview_addDebtButton"
android:layout_gravity="center_horizontal"
android:layout_weight="1.0"
/>
</LinearLayout>
</FrameLayout>
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
The drawer is given a fixed width in dp and extends the full height of
the container. A solid background is used for contrast
with the content view. -->
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
This fails woefully when I try to run the app and i get a android.view.InflateException with the error message:
error inflating class DrawerLayout. Am not sure how to proceed from here. "There is a similar question that asks "How do I add navigation drawer to my existing code?" but this problem is way too complicated than mine and I can't apply the solutions to my problem. Any suggestions will be appreciated.
Try like this:
According to docs: Drawer Layout tooks two direct children
Inside the DrawerLayout, add one view that contains the main content
for the screen (your primary layout when the drawer is hidden) and
another view that contains the contents of the navigation drawer.
From that reference I used one for FrameLayout and another one for ListView.
<?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/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/container"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<ListView
android:id="#+id/itemlistView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:layout_weight="1.0"
tools:ignore="ObsoleteLayoutParam" />
<Button
android:id="#+id/listview_addDebtButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1.0"
android:background="#drawable/button"
android:text="#string/new_item"
tools:ignore="ObsoleteLayoutParam" />
</RelativeLayout>
</FrameLayout>
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
I am working on a project where there is a navigation drawer.In the navigation drawer , i want to place an imageview above a listivew.The xml layout is as follows:
<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" >
<!-- The main content view -->
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<!-- The navigation drawer -->
<RelativeLayout
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical"
android:clickable="true"
>
<ImageView
android:id="#+id/image_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/ic_logo" />
<ListView
android:id="#+id/slider_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#CC000000"
android:choiceMode="singleChoice"
android:divider="#808080"
android:layout_below="#id/image_view"
android:dividerHeight="0.5dp"
/>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
The issue is that the imageview appears squished/compressed on running on a device.Why does it appear to be compressed?Please help!!
To answer your question:
you have the imageView width set to "match_parent" and height set to "wrap_content" which is going to cause the image to stretch horizontally unless it is the same width as the device - set the width to "wrap_content" and center the image if necessary.
also...
Relative layouts don't have orientation so you should remove the line -
android:orientation="vertical"
Use this attribute in your imageview:
android:adjustViewBounds="true"
Also, use the src attribute for the drawable, not the background attribute:
android:src="#drawable/my_drawable"
I have a layout called footer.xml which later will be included to multiple layouts. Footer.xml is as follows:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/bottomMenu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:background="#drawable/bg_gradation"
android:weightSum="1" >
*** STUFF GOES HERE ***
</LinearLayout>
Footer.xml will then be included in other layout as follows..
<?xml version="1.0" encoding="utf-8"?>
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<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"
android:background="#drawable/backrepeat">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<LinearLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginBottom="0dp"
android:weightSum="1">
<ListView
android:id="#+id/chatListView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:divider="#00000000"
android:scrollbars="none"
android:dividerHeight="1dp"
android:layout_weight=".80"/>
<LinearLayout
android:id="#+id/chatBar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".13"
android:orientation="horizontal"
android:background="#242424"
android:weightSum="1">
</LinearLayout>
</LinearLayout>
<include layout="#layout/footer"/>
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
The drawer is given a fixed width in dp and extends the full height of
the container. A solid background is used for contrast
with the content view. -->
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
Since i want footer.xml be at the bottom screen, i use android:layout_gravity="bottom" this renders properly if seen from the perspective of footer.xml
However, when i try to see it from other layouts it throws error that says:
java.lang.UnsupportedOperationException (Error Log does not show helpful information at all).
EDIT 1
This is the best error message i could get.. (i cannot copy-paste the log text)
EDIT 2
IF i include my layout this way:
<LinearLayout
android:layout_weight="1"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include layout="#layout/footer"
android:id="#+id/footer"/>
</LinearLayout>
It renders the way i want it inside eclipse editor. However, when i try to run it on Android i get the following error:
java.lang.IllegalStateException: Child android.widget.LinearLayout{a72d4938 V.E..... ......ID 0,0-0,0 #7f0a005c app:id/bottomMenu} at index 1 does not have a valid layout_gravity - must be Gravity.LEFT, Gravity.RIGHT or Gravity.NO_GRAVITY
and if i editted my footer.xml to this:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/bottomMenu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" <---- not android:layout_gravity="bottom"
android:background="#drawable/bg_gradation"
android:weightSum="1" >
my footer would fill up the entire screen from top to bottom.
Can anyone help me with this? Thanks..
Put you linearLayout and footer inside relative layout
<include
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
layout="#layout/activity_main" />
XML:
<?xml version="1.0" encoding="utf-8"?>
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<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"
android:background="#drawable/backrepeat">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/content_frame"
android:layout_above="#+id/footer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginBottom="0dp"
android:weightSum="1">
<ListView
android:id="#+id/chatListView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:divider="#00000000"
android:scrollbars="none"
android:dividerHeight="1dp"
android:layout_weight=".80"/>
<LinearLayout
android:id="#+id/chatBar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".13"
android:orientation="horizontal"
android:background="#242424"
android:weightSum="1">
</LinearLayout>
</LinearLayout>
<include layout="#layout/footer" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
The drawer is given a fixed width in dp and extends the full height of
the container. A solid background is used for contrast
with the content view. -->
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
I've been trying to make a DrawerLayout that has a ViewPager and a LinearLayout attached to the bottom of the DrawerLayout. The problem is that the ViewPager and LinearLayout are overlapping at the top of the view, and all my efforts to move the LinearLayout down have failed so far.
The XML 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" >
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0dp" >
<android.support.v4.view.PagerTabStrip
android:id="#+id/tabstrip"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</android.support.v4.view.ViewPager>
<LinearLayout
android:id="#+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="#id/base_activity_viewpager"
android:orientation="vertical" >
<TextView
android:id="#+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textAppearance="#android:style/TextAppearance.Medium"
android:textIsSelectable="false" />
</LinearLayout>
<!-- Naviagtion drawer -->
<ListView
android:id="#+id/drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
I've tried adding several things to linear_layout:
android:layout_gravity="bottom" (causes an IllegalStateException)
android:layout_below="#id/viewpager"
android:layout_alignparentbottom="true"
But all of these values seem to be ignored, even changing android:layout_width of the LinearLayout is ignored. I think i'm overlooking something obvious but if anyone has suggestions on how to do this it would be greatly appreciated.
A drawerlayout is allowed only 2 children, the first is a main content view, the second is the drawer. You need to combine your first two views into a linear layout. http://developer.android.com/training/implementing-navigation/nav-drawer.html