Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create view over cardview in android

Tags:

I want to create this layout
enter image description here

this is a cardview (gray view) and imageview(blue view) for that i use this code

<FrameLayout 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:background="@color/abc_search_url_text_normal"
android:orientation="vertical">

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_alignParentBottom="true"
    android:layout_gravity="bottom"
    android:layout_marginBottom="3dp"
    android:paddingTop="5dp"
    app:cardBackgroundColor="@color/abc_input_method_navigation_guard">


</android.support.v7.widget.CardView>

<ImageView
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_gravity="bottom"
    android:layout_marginBottom="30dp"
    android:layout_marginRight="10dp"
    android:scaleType="fitXY"
    android:src="@drawable/abc_ratingbar_full_material" />

</FrameLayout>

but in result my image view going to back of cardview i try reletivelayout instead of framelayout but same result.

like image 888
max Avatar asked Nov 20 '15 09:11

max


People also ask

How do I customize my CardView?

Customized CardView First, add a CardView dependency to the application-level build. gradle file. Then create a drawable background for the cards. For that, create a new drawable resource file inside the drawable folder.

What is CardView in Android with example?

CardView is a new widget in Android that can be used to display any sort of data by providing a rounded corner layout along with a specific elevation. CardView is the view that can display views on top of each other. The main usage of CardView is that it helps to give a rich feel and look to the UI design.

What is cardUseCompatPadding?

What is cardUseCompatPadding? For a more consistent UI, use cardUseCompatPadding=true. CardView adds additional padding to draw shadows on platforms before Lollipop. This may cause Cards to have different sizes between Lollipop and before Lollipop.


1 Answers

The CardView has by default elevation in API 21+, you can manipulate the elevation to be less than that of the ImageView

    <android.support.v7.widget.CardView  xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     app:cardElevation="1dp"/>

 <ImageView
        android:id="@+id/image_view_user"
        android:layout_width="48dp"
        android:layout_height="48dp"
         android:elevation="2dp"/>

in Pre 21 you can use

overlayView.bringToFront();
root.requestLayout();
root.invalidate();

This will not work in 21+ if you have different elevation

like image 184
atabouraya Avatar answered Oct 05 '22 06:10

atabouraya