I have an ImageView and a CheckBox inside a FrameLayout. Although the CheckBox is placed above the ImageView, its ripple feedback is drawn below the ImageView. Is there any way to draw the ripple on top? Tried adding elevation values but nothing changed.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:layout_height="285dp"
android:layout_width="300dp"
android:src="#drawable/rectangle"
android:layout_gravity="center_horizontal|top" />
<CheckBox
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New CheckBox" />
</FrameLayout>
Seems that the ripples are drawn on top of their container's background. So I put the CheckBox in another container, set the container's background to transparent and the ripple showed up correctly.
Related
I'm trying to make a trimmerbar to my video player
trimmer_bar.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/thumbsBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
tools:background="#color/trimmerBarSelected">
<ImageView
android:id="#+id/leftThumb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription=""
android:scaleType="fitStart"
android:src="#drawable/ic_left_thumb" />
<ImageView
android:id="#+id/rightThumb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:contentDescription=""
android:scaleType="fitEnd"
android:src="#drawable/ic_right_thumb" />
</RelativeLayout>
<ImageView
android:id="#+id/progressIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="60dp"
android:layout_marginTop="3dp"
android:contentDescription=""
android:scaleType="centerCrop"
android:src="#android:drawable/btn_star_big_on" />
</FrameLayout>
activity_video_viewer:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#a8c71c"
tools:context=".activities.VideoTrimmerActivity">
<com.tomatedigital.instagram.longstories.ui.TrimmerBar
android:id="#+id/trimmerBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/trimmerBarSelected"
/>
</FrameLayout>
it's logic is working great: when the user touches, i detect if it was on the any of the thumbs and case on the left thumb I adjust the left margin of the thumbsBar, case on the right I adjust the right margin...
As the two imageview are aligned to the edges this behavior makes them to move... but what is actually moving is the whole RelativeLayout
The problem is even adjuting the margins and moving the imageviews the relative layout is still showing the background in the margin area
ignoring the whole calculation i set the margins using:
this.thumbsBar= (RelativeLayout) findViewById(R.id.thumbsBar);
this.thumbsBarLayout = (LayoutParams) this.thumbsBar.getLayoutParams();
this.thumbsBarLayout.leftMargin = this.leftMargin;
this.thumbsBarLayout.rightMargin = this.rightMargin;
this.thumbsBar.setLayoutParams(this.thumbsBarLayout);
===============================================================
UPDATE:
to make it easier to understand
I've this:
I should have:
com.tomatedigital.instagram.longstories.ui.TrimmerBar has the same background as your RelativeLayout and has a width of match_parent. You don't really specify how your layout is being loaded and I assume it is in your custom view.
For a test, change the color of the background of the custom view to see if the background you are seeing in the margins is coming from the RelativeLayout or the custom view. My guess is that it's coming from the custom view and changing the background color in the custom view will solve your problem.
I have created a list item (as shown in the picture) with an ImageView (The beautiful Miranda Kerr) and an ImageButton (The trash icon) with background selectableItemBackgroundBorderless.
Now, when I click on the trash icon, the ripple is created behind the ImageView
Naturally, I want the ripple to take place in front of the image and behind the trash icon.
Full item.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/image_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
tools:src="#drawable/cover"
/>
<ImageButton
android:id="#+id/trash_image_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:src="#drawable/translucent_trash"
android:background="?attr/selectableItemBackgroundBorderless"
/>
</FrameLayout>
This is the same problem in : Ripple behind other view
You can wrapp your button by a FrameLayout with a background transparent.
I have the following layout:
<?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:id="#+id/create_workout_fab_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_horizontal_margin"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#drawable/fab"
android:stateListAnimator="#anim/fab_elevation"
android:clickable="true"
>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/create_workout_fab_anim_helper"
android:layout_width="#dimen/fab_size"
android:layout_height="#dimen/fab_size"
card_view:cardBackgroundColor="#color/primary_dark"
card_view:cardCornerRadius="#dimen/fab_radius"
android:visibility="invisible"
/>
<TextView
android:id="#+id/create_workout_fab_label"
android:layout_width="#dimen/fab_size"
android:layout_height="#dimen/fab_size"
android:background="#drawable/fab_ripple_selector"
android:textAppearance="?android:textAppearanceLarge"
android:text="+"
android:textColor="#color/fab_label_color"
android:duplicateParentState="true"
android:gravity="center"
tools:text="+"
tools:textColor="#color/fab_label_color"
/>
</FrameLayout>
The CardView is only there to use it for an smooth animation from a cirle button to a rectangle view by animation a radius change.
But the problem is, wheneever the CardView becomes visible it stays above the TextView. Why is that and how do I get it to lay under the TextView
FrameLayout draws children in order, first to last. Therefore you need to swap the CardView with the TextView.
UPDATE:
Also if you are running on android L+ you need to set a higher elevation on the CardView than the TextView
I want to do this efect:
The last linear layout contains a circle in an ImageView and the background is set from the center to the end, how can I do this?
Using a shape doesn't work fine..
You can either use a stretched image as background, or have multiple layers of views.
In the latter way you can have a RelativeLayout, a background view, and the foreground view:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="48dp">
<View
android:layout_width="fill_parent"
android:layout_height="32dp"
android:layout_alignParentBottom="true"
android:background="#808080" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
text="This is the foreground" />
</RelativeLayout>
I have a ScrollView with some elements.
My problem is that i can't set textview's above ImageView's with dynamical height.
I have 3 ImageView with different height, they can be visible or gone.
Above them i need to put text with background color, this text need to be at the bottom part of the ImageView
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/pic"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ImageView>
<TextView
android:id="#+id/third_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:padding="8dp"
android:layout_alignParentBottom="true"
android:layout_above="#id/third_picture"
android:gravity="center_horizontal"
android:background="#android:color/white"
android:text="example text">
</TextView>
I tried a lot, but my View was always broken.
Please help, i need some proffesional advise.
You can do this in textview:
android:layout_alignBaseline="#id/pic"
This will align the baseline of textview with basline of imageview
You can set your picture as a background for a layout (e.g linear layout ) rather than using an ImageView and then put the textview inside it and place it where ever you want.
<LinearLayout
android:background="your picture" >
<!-- align it to the bottom -->
<TextView
/>
</LinearLayout>