I am trying to use a BottomSheet in my layout.
The root view is an CoordinatorLayout and I want to set Elevation on top for the Bottom Sheet so i am setting it with a high value (50dp), however it is not showing when the app runs but it appears on android studio design tool.
I have tried to set background for the sheet with a solid color instead of gradient but it still did work. I also tried to use Shadow shapes but it does not give the same elevation appearance.
here is my XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.atefhares.StartActivity"
android:clipToPadding="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/DetailsView"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Details Should be shown here"
android:id="#+id/textView"
android:textSize="25sp"
android:padding="20dp" />
</LinearLayout>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.atefhares.Start_Activity" />
</LinearLayout>
<android.support.v4.widget.SlidingPaneLayout
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:behavior_peekHeight="70dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:background="#drawable/gradiant"
android:fillViewport="true"
android:elevation="50dp">
<include layout="#layout/bottom_sheet_layout"/>
</android.support.v4.widget.SlidingPaneLayout>
</android.support.design.widget.CoordinatorLayout>
Edit:
bottom_sheet_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#color/colorPrimary"
android:padding="10dp"
android:id="#+id/inviteLL">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/imageView"
android:background="#drawable/invite_icon"
android:layout_margin="5dp"
android:layout_gravity="center_vertical" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Invite Friends"
android:textSize="22sp"
android:textColor="#ffffff"
android:padding="10dp"
android:fontFamily="sans-serif-condensed"
android:gravity="center_vertical"
android:id="#+id/inviteTV"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/arrowIV"
android:layout_gravity="center_vertical"
android:background="#drawable/arrow_up" />
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="#+id/usersLV"
android:dividerHeight="1dp"
android:divider="#ffffff"
android:background="#ffffff" />
</LinearLayout>
So how can I make the elevation shows on top of the Bottom Sheet
Any one can help, please ?
Try this,
<android.support.v4.widget.SlidingPaneLayout
android:id="#+id/bottom_sheet"
xmlns:slide_panel="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:behavior_peekHeight="70dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:background="#drawable/gradiant"
android:fillViewport="true"
slide_panel:elevation="50dp">
According to the google guidelines with the android:elevation is not possible (Also you can read more about the keyligth).
Anyway on the most common cases when you scroll up the "BottomSheet" a semitransparent layer appears behind the "BottomSheet", this helps to keep the user focus on the "BottomSheet" actions, like these examples.
If anyway you want a top shadow you can set a drawable background with gradient like this (shadow_top.xml):
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="90"
android:centerColor="#000000"
android:endColor="#android:color/transparent"
android:startColor="#000000"
android:type="linear" />
And your SlidingPanelLayout will be:
<android.support.v4.widget.SlidingPaneLayout
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:behavior_peekHeight="95dp"
android:paddingTop="25dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:background="#drawable/shadow_top"
android:fillViewport="true"
>
Best regards.
Do not forget that to draw shadow you must use hardwareAccelerated drawing
hardwareAccelerated = true
hardwareAccelerated = false
See Android Hardware Acceleration for details
The answer is: no, it is not possible (unless you create your own view custom with an elevation feature on top).
Elevetion is not meant to be visible in the top of a view, but in the bottom, on the right and on the left.
If you see closely on the official Material Design guidelines, you can see that the bottom bar simply don't have it (do not confuse with the gray space between the card and the bottom bar).
For example: import Card View sample from Android Studio and play with it with emulator or your device. You will see that if you increment the elevation value, the view will have his shadow everywhere except on top (see second image below).
Another example is given by importing Elevation Basic.
EDIT
Following code is taken from Card View sample. There is a layout containing a CardView with elevation. Whenever you change the elevation, you will always see shadow everywhere, but not on top (the code was tested with Lollipop and Marshmallow).
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
>
<android.support.v7.widget.CardView
android:id="#+id/cardview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:elevation="100dp"
card_view:cardBackgroundColor="#color/cardview_initial_background"
card_view:cardCornerRadius="8dp"
android:layout_marginLeft="#dimen/margin_large"
android:layout_marginRight="#dimen/margin_large"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_medium"
android:text="#string/cardview_contents"
/>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_large"
android:orientation="horizontal"
>
<TextView
android:layout_width="#dimen/seekbar_label_length"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="#string/cardview_radius_seekbar_text"
/>
<SeekBar
android:id="#+id/cardview_radius_seekbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_medium"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:layout_width="#dimen/seekbar_label_length"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="#string/cardview_elevation_seekbar_text"
/>
<SeekBar
android:id="#+id/cardview_elevation_seekbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_medium"
/>
</LinearLayout>
</LinearLayout>
Related
I am trying to implement a screen with a map and on top on the map it should have a textbar displaying text but for some reason my textbar always goes below the google map view.
I tried to look up for relateable questions but no success with their answers. The picture is attached below to give some more gudience. Code is below.
<?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"
android:paddingStart="20dp"
android:paddingEnd="20dp">
<com.google.android.gms.maps.MapView
android:id="#+id/map"
android:elevation="10dp"
android:layout_below="#+id/tv_treatment_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/tv_rateDoctor"
>
</com.google.android.gms.maps.MapView>
<include
android:id="#+id/toolbar"
layout="#layout/menu_top_header"
android:layout_width="match_parent"
android:layout_height="#dimen/custom_toolbar_height"
/>
<TextView
android:id="#+id/tv_treatment_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
android:layout_marginBottom="20dp"
android:layout_centerHorizontal="true"
android:text="Treatment ID: 222-X-F"
android:textSize="#dimen/font_label" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tv_information"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_alignTop="#+id/map"
android:orientation="horizontal"
android:background="#color/colorTextGrey"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_sent_info"
android:padding="20dp"
android:text="Your Treatment has been sent to the following lab"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:padding="20dp"
android:id="#+id/tv_rateDoctor">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/rate_doctor"
android:textSize="#dimen/font_input"
android:fontFamily="#font/lato_bold"
/>
<ImageView
android:layout_marginStart="5dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:srcCompat="#drawable/ic_arrow_right"
android:layout_marginLeft="30dp" />
</LinearLayout>
Image of desirable output
Try the next layout. If you want to display something in front then you must put it at last in the layout.
EDIT
Try this code instead. I´m using it in a personal project and show buttons in front of the map. But of course im using a SupportMapFragment, maybe you can try using it too.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<fragment
android:id="#+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="250dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
android:gravity="top">
<!-- Put any TextView, Imageview, Button, etc inside -->
<LinearLayout/>
</FrameLayout>
Hope it helps!
try using this in your textView
android:layout_alignParentTop="true"
layout_alignParentTop
If true, makes the top edge of this view match the top edge of the
parent. Accommodates top margin.
May be a boolean value, such as "true" or "false".
You can also try using
android:layout_alignTop
which Makes the top edge of this view match the top edge of the given anchor view ID. Accommodates top margin.
So I want to use 2 images. One should be on top of the other but smaller, so that the border of the image that's behind is only shown.
Take a look at these 2 photos.
Image that's behind (The border Image)
[IMG]http://i66.tinypic.com/25zgguh.jpg[/IMG]
Image that should be inside the border
[IMG]http://i67.tinypic.com/10mpgt4.jpg[/IMG]
XML CODE
<com.inthessaloniki.cityguide.view.SelectorRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment_poi_list_item"
android:layout_width="match_parent"
android:layout_height="#dimen/fragment_poi_list_recycler_item_size"
android:minHeight="#dimen/fragment_poi_list_recycler_item_size"
android:listSelector="#drawable/selector_clickable_item_bg_inverse">
<ImageView
android:id="#+id/fragment_poi_list_item_image"
android:layout_width="match_parent"
android:layout_height="#dimen/fragment_poi_list_recycler_item_size"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/fragment_poi_list_recycler_item_panel_height"
android:layout_alignParentBottom="true"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingLeft="#dimen/global_spacing_xs"
android:paddingRight="#dimen/global_spacing_xxs"
android:background="#color/fragment_poi_list_recycler_item_panel_bg">
<TextView
android:id="#+id/fragment_poi_list_item_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="#style/TextAppearance.CityGuide.Body1.Inverse"
android:fontFamily="sans-serif"
android:maxLines="2"
android:ellipsize="end" />
<TextView
android:id="#+id/fragment_poi_list_item_distance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_grid_distance"
android:drawablePadding="#dimen/fragment_poi_list_recycler_item_icon_padding"
android:textAppearance="#style/TextAppearance.CityGuide.Body1.Inverse"
android:fontFamily="sans-serif"
android:maxLines="1"
android:ellipsize="end" />
</LinearLayout>
I was thinking if I could add an android:background="First Image" and make my Image view center but leaving some space on the edges for the background to be shown.
Would have posted 2 more images showing how the app is and how it should look, but the site won't let me post more than 2 links cause my reputation is lower than 10 -_-
Thanks in advance for the help!!!
Do it like this:
<com.inthessaloniki.cityguide.view.SelectorRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment_poi_list_item"
android:layout_width="match_parent"
android:layout_height="#dimen/fragment_poi_list_recycler_item_size"
android:minHeight="#dimen/fragment_poi_list_recycler_item_size"
android:listSelector="#drawable/selector_clickable_item_bg_inverse">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background_image"
tools:context=".MainActivity">
<ImageView
android:id="#+id/view"
android:layout_margin="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/foreground_image" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/fragment_poi_list_recycler_item_panel_height"
android:layout_alignParentBottom="true"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingLeft="#dimen/global_spacing_xs"
android:paddingRight="#dimen/global_spacing_xxs"
android:background="#color/fragment_poi_list_recycler_item_panel_bg">
<TextView
android:id="#+id/fragment_poi_list_item_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="#style/TextAppearance.CityGuide.Body1.Inverse"
android:fontFamily="sans-serif"
android:maxLines="2"
android:ellipsize="end" />
<TextView
android:id="#+id/fragment_poi_list_item_distance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_grid_distance"
android:drawablePadding="#dimen/fragment_poi_list_recycler_item_icon_padding"
android:textAppearance="#style/TextAppearance.CityGuide.Body1.Inverse"
android:fontFamily="sans-serif"
android:maxLines="1"
android:ellipsize="end" />
</LinearLayout>
hope I got it clear, you could simply use two layout and adjust margin for the small one.
put your images as RelativeLayout background or use ImageView in layouts
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="25dp"></RelativeLayout>
</RelativeLayout>
I'm currently using a library that allows me to move freely a CardView in my screen, based on the user's finger. Here's my problem: I have a view Group on top that needs to stay below that CardView, but I'm not managing to do so.
I've tried using Frame Layout, but it didn't work as planned. The best I could do was that
but still, not what I meant to dO (card view completely floating around the "toolbar")
<?xml version="1.0" encoding="utf-8"?>
<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"
android:id="#+id/framelayout"
android:background="#color/verdeClaro"
tools:context=".View.Activity.LeitorMbookActivity"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:isScrollContainer="true"
>
<com.wenchao.cardstack.CardStack
android:elevation="4dp"
android:layout_marginTop="32dp"
android:id="#+id/cardStackContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding = "20dp"
android:clipChildren="false"
android:clipToPadding="false"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="64dp"
android:layout_gravity="top"
android:background="#android:color/transparent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="15"
android:gravity="center_vertical|right"
>
<ImageView
android:id="#+id/home_icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="#drawable/ic_home"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="center_vertical"
>
<com.akexorcist.roundcornerprogressbar.RoundCornerProgressBar
android:id="#+id/progress_bar"
android:layout_height="6dp"
android:layout_width="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="24dp"
app:rcProgressColor="#color/white"
app:rcBackgroundColor="#color/verde_musgo"
app:rcRadius="2dp"/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
The library I'm using to move the card is that.
I have my main home screen, but after it loads I want to display an overlaid wheel selector that will go away once a choice is made. Everything has gone well so far except that the submit button for the wheel selector is having some transparency forced upon it.
I've tried android:alpha to force it to be fully opaque but that has not had an effect. Here is the xml layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:textColor="#000000"
android:background="#faff67"
>
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
[ Not relevant? ]
</LinearLayout>
<RelativeLayout android:id="#+id/wheelView" android:background="#CC000000"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical">
<kankan.wheel.widget.WheelView android:id="#+id/deptWheel"
android:layout_height="110dp"
android:layout_width="wrap_content"
android:layout_weight="1"/>
<Button android:id="#+id/button_selectDept"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:alpha="1"
android:text="Submit"></Button>
</LinearLayout>
</RelativeLayout>
Any ideas for what I'm doing wrong here?
Maybe throw in a background for the button:
android:background="#FFFFFF"
Or change the color alpha:
android:color="#FF000000"
Perhaps both:
android:background="#FFFFFFFF"
I am novice in Android trying to make this layout:
Simply what I want to achieve:
The red container should take as much space as it needs but not as much that green container have to be shrinked. If there are too many items, red container will be scrollable. Green container is also always centered in orange one if there is space for it (if not it is actually still centered).
I don't know how to do it at all :( . Here is my try:
The problem is that I want to always maintain height of green container (minHeight does not work I can't understand why) and make the green container centered in orange one. I have problem with Scenario 2 (as you can see in the picture), this code works good in first scenario.
<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"
android:orientation="vertical">
<ScrollView
android:id="#+id/red_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/holo_red_dark"
android:scrollbarAlwaysDrawVerticalTrack="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Items are here -->
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/orange_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/holo_orange_dark"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:id="#+id/green_container"
android:layout_width="100dp"
android:background="#android:color/holo_green_dark"
android:layout_height="50dp"
android:orientation="horizontal">
<!-- My content -->
</LinearLayout>
</LinearLayout>
</LinearLayout>
Edit: minHeight does not help:
Edit: image for user Illegal Argument:
Try setting property android:minHeight = "(whatever)dp" to orangeContainer. This worked for me in others "similiar" cases.
:)
Is this what you are looking for:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/list_items"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#android:color/background_dark" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/list_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#android:color/darker_gray"
android:gravity="center"
android:minHeight="200dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</RelativeLayout>
Snapshot in ecllipse: