I have a dialog which contains a CardView with cornerRadius set, StreetViewPanoramaView is at top, but top corners are square, I guess it's a SurfaceView, any hint about how to make the corners round above StreetViewPanoramaView?
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:clipChildren="true"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="16dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.google.android.gms.maps.StreetViewPanoramaView
android:id="#+id/street_view"
android:layout_width="match_parent"
android:layout_height="150dp" />
[...]
Try app:cardUseCompatPadding="true" maybe help you I am not sure because I used with another component not StreetViewPanoramaView so please try it.
Related
I'd like to start by showing what I'm trying to achieve, and I'll move on to what I I know and have tried.
• What I've tried:
I've tried Collapsing Toolbar Layout, which doesn't give the effect that's in the image, where the bottom view with Title and description is stacked on Top of ImageView.
I used BottomSheet, but unfortunately I don't see any way to anchor the BottomSheet to the bottom of ImageView, I tried to do it using app:layout_anchor="#id/imageView", but it still covers the complete image, and without that, it does as intended, but it doesn't stay below the ImageView, if the image is long, it'll cover a lot of part of that image.
I tried the following layout, (where #drawable/background_blog_description is the drawable with rounded corners at top). Also, in the layout below, I haven't added layout_anchor tag because it covers entire Image (Even if I specify the anchor_gravity="bottom").
<androidx.coordinatorlayout.widget.CoordinatorLayout
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:orientation="vertical">
<ImageView
android:id="#+id/iv_notice_image_complete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:transitionName="iv_notice_image" />
<androidx.core.widget.NestedScrollView
android:id="#+id/acm_nsv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:behavior_hideable="false"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background_blog_description"
android:orientation="vertical"
android:paddingStart="20dp"
android:paddingTop="20dp"
android:paddingEnd="20dp"
android:paddingBottom="100dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<TextView
android:id="#+id/tv_notice_title_complete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="56dp"
android:padding="5dp"
android:text="This will be the title of notice"
android:textColor="#color/black"
android:textSize="30sp"
android:textStyle="bold"
android:transitionName="tv_notice_title" />
<WebView
android:id="#+id/mdv_notice_description_complete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:transitionName="tv_notice_description" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab_notice_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_gravity="top|start"
android:layout_margin="8dp"
app:backgroundTint="#color/white"
app:srcCompat="#drawable/ic_back" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
At this point I'm kinda blank as to what I should do to make something like below. It must be something really simple, but I'm not seeing it for some reason. My only requirement is that the bottom Layout/View of the ImageView should be on top of it, with a small part of Image (20dp maybe?) under that view, and when scrolled, it should cover the image.
So, BottomSheet which can be anchored at the bottom of ImageView, but with some part of Image going under the BottomSheet?
Put your image within an AppBarLayout and then add app:behavior_overlapTop=20dp to your NestedScrollView.
https://developer.android.com/reference/android/support/design/widget/AppBarLayout.ScrollingViewBehavior.html#setOverlayTop(int)
CardView for Android has black spaces, how to remove it. i need help.
this is java or android problem.
enter image description here
<android.support.v7.widget.CardView
android:id="#+id/cv_result_knowledge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/ll_result_header"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
android:visibility="gone"
app:cardBackgroundColor="#color/black_transparent40"
app:cardCornerRadius="#dimen/d12"
app:cardElevation="#dimen/d1"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/d10"
android:layout_marginTop="#dimen/d2">
</RelativeLayout>
</android.support.v7.widget.CardView>
Its because you set the background color to black, your Relative Layout has margin set so the black card background is visible in the margin area. Just remove the card background or remove margins, whichever suits you.
<android.support.v7.widget.CardView
android:id="#+id/cv_result_knowledge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/ll_result_header"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
android:visibility="gone"
app:cardBackgroundColor="#color/black_transparent40" -<REMOVE THIS
app:cardCornerRadius="#dimen/d12"
app:cardElevation="#dimen/d1"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/d10" -<REMOVE THIS
android:layout_marginTop="#dimen/d2"> -<REMOVE THIS
i have an imageview on a relative layout.
You can see in the screenshot :
How can i move the imageview(the weel) in the bottom-right corner, but display only 25 % part of it, like in the follow picture:
Thanks in advance !
<?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"
android:background="#E0E0E0"
>
<com.androidsources.welcomescreen.MyRecyclerView
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:id="#+id/cardList"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<com.anupcowkur.wheelmenu.WheelMenu
android:id="#+id/wheelMenu"
android:layout_width="300dp"
android:layout_height="300dp"
android:src="#drawable/wheel"/>
</RelativeLayout>
You can try something like this:
<com.anupcowkur.wheelmenu.WheelMenu
android:id="#+id/wheelMenu"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:paddingLeft="150dp"
android:paddingTop="150dp"
android:src="#drawable/wheel"/>
alignParentRight and alignParentBottom attributes will move your widget at the right bottom corner. Also try to change padding to achieve desired visual effect.
I know that there is already an answer, but for those who can't make the accepted answer work here is an alternative.
For some reason, I can't place part of the view outside the parent if I'm using RelativeLayout but when I tried LinearLayout it worked. So the solution I used is to enclose the view in a LinearLayout then position the LinearLayout on bottom-end of the parent.
<LinearLayout
android:layout_width="300dp"
android:layout_height="300dp"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true">
<ImageView
android:layout_width="300dp"
android:layout_height="300dp"
android:src="#drawable/some_pic"
android:layout_marginStart="150dp"
android:layout_marginTop="150dp"/>
</LinearLayout>
Note the width and height of the image is not match_parent, using match_parent will shrink the image not displace it.
I have set up a CardView in a RecyclerView list. The layout_marginTop and layout_marginBottom are showing a grey color rather than the white background I had hoped to see (image below). Any ideas on how to get the top and bottom margins to show a white background?
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardCornerRadius="6dp"
android:layout_margin="4dp">
<TextView
android:id="#+id/cardText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:background="#android:color/white" />
</android.support.v7.widget.CardView>
Removed the TextView background and added this background to the CardView:
"card_view:cardBackgroundColor="some color""
Add some margin to card
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="7dp"
app:cardCornerRadius="2dp"
app:cardElevation="4dp">
</android.support.v7.widget.CardView>
Make sure you're actually populating it with data from your domain model, i.e. check that you've implemented <data> and <variable> tags and that you've set your android:text="#{}" to the appropriate object.
I have this LinearLayout that is going to be placed on the bottom of an activity layout. I want this LinearLayout to have a 4dp elevation, just like the top toolbar should have, however, since android:elevation places the shadow below the ui component and this specific component (linearLayout) is going to be on the bottom of the screen, I won't see any elevation at all..
This is my LinearLayout code, and an image of it with the default elevation implemented:
<?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="wrap_content"
android:weightSum="3"
android:background="#android:color/transparent"
android:orientation="horizontal"
android:elevation="4dp"
android:layout_alignParentBottom="true">
<ImageButton
android:id="#+id/playButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="center"
android:clickable="true"
android:background="#drawable/bottom_toolbar_menu_selector"
android:src="#drawable/ic_play"
style="?android:attr/borderlessButtonStyle" />
<ImageButton
android:id="#+id/stopButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="center"
android:clickable="true"
android:background="#drawable/bottom_toolbar_menu_selector"
android:src="#drawable/ic_stop"
style="?android:attr/borderlessButtonStyle" />
<ImageButton
android:id="#+id/bookmarkButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="center"
android:clickable="true"
android:background="#drawable/bottom_toolbar_menu_selector"
android:src="#drawable/ic_bookmark"
style="?android:attr/borderlessButtonStyle" />
</LinearLayout>
Is there a way, using elevation to place a shadow on top of the ui component?
Thanks in advance!
You can't theoretically do it with android:elevation, in the sense that you can't choose the direction where the shadow is going to be cast.
There are two solutions.
1. Drawables
You could, for instance, put an ImageView right above your layout and set android:src="#drawable/shadow". This should be a vertical GradientDrawable defined in XML, as explained here.
2. Workaround
While most of the shadow is actually below the view, a subtle shadow is also above. A workaround might be using a very high value for elevation, like 40dp: the bottom part is going to be hidden due to your layout, while the top is going to be expanded and look like a common shadow.
In either case, you do not have control over the elevation value in dp, in the sense that you can't be sure your shadow is equivalent to the one cast by android:elevation=4dp.
use like as;
<LinearLayout
android:layout_width="match_parent"
android:layout_height="205dp"
android:background="#color/white"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="-5dp"
android:background="#color/white"
android:elevation="3dp"
android:paddingTop="5dp">
// CHILD VIEWS
</RelativeLayout>
</LinearLayout>
Add this code above of view in which you want top elevation or add android:layout_marginTop="-4dp" and add below of above view
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="0.01dp"
android:layout_below="#+id/scrollbar"
app:cardBackgroundColor="#android:color/transparent"
app:cardCornerRadius="0dp"
app:cardElevation="#dimen/dp_4" />
Try this i am unable to set background through xml then i tried the programmatic way to solve that and i work perfectly refer this if facing problem on show shadow in Linear Layout
lprofile.setBackgroundResource(R.drawable.background_with_shadow);
lprofile is my ref of Linear layout and background_with_shadow is xml for applying shadow i hope i will for ur requirmement...thank u..