Elevated base android - android

I'm trying to add an elevated base to an layout and I can't manage to do that. If someone know how to help me a little it would be appreciated.
This is the base I want to get:

You can simple achieve this using MaterialCardView by following code snippet :
<com.google.android.material.card.MaterialCardView
android:layout_margin="8dp"
android:layout_width="match_parent"
android:layout_height="100dp"
app:cardCornerRadius="0dp"
app:cardElevation="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--Rest of your layout code goes here-->
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
Happy Coding :)

Related

How can I keep circleimageview ahead of a CardView? in ConstraintLayout?

I want to show output in such a way that CircleImageView is ahead of CardView
But my output looks like this
This is my Single Row XML which I want to use with RecylerView
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/backgroundColor">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/circleImageView"
android:layout_width="90dp"
android:layout_height="90dp"
android:src="#drawable/cat_placeholder"
app:civ_border_color="#color/red"
app:civ_border_width="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="32dp"
app:cardElevation="50dp"
app:layout_constraintBottom_toBottomOf="#+id/circleImageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/circleImageView"
app:layout_constraintTop_toTopOf="#+id/circleImageView" />
</androidx.constraintlayout.widget.ConstraintLayout>
Consider wrapping your CardView and CircleImageView in a FrameLayout. Also, set the android:elevation property for both views in the way that you want them to appear.
<FrameLayout
android:id="#+id/some_container"
android:layout_width="..."
android:layout_height="..."
... >
<CardView
android:id:"#+id/card"
android:layout_width="..."
android:layout_height="..."
android:elevation="..."
...
... />
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/circleImageView"
android:layout_width="90dp"
android:layout_height="90dp"
android:src="#drawable/cat_placeholder"
android:elevation="..."
...
... />
</FrameLayout>
Don't forget to check the FrameLayout documentation for understanding how best to use it. (Also, remember that a CardView is itself a FrameLayout.)
Additionally, I would suggest paying attention to the minSdkVersion of your project. The elevation property is available in API 21+ . Your app won't crash in lower API devices, but you might not get the look you need. Strongly consider using the FrameLayout for achieving overlap, or try designing custom views or using some library, e.g. for shadows to simulate elevation.
add android:elevation="55dp" to your imageView

how to fix CardView Corner radius issue?

I'm using below code to create a CardView with corners but it stay rectangular
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/cardview_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardCornerRadius="6dp">
UPDATE : there was a mistake in my Manifest i just remove this line:
android:hardwareAccelerated="false"
I also had same issue. The issue I found is...
android:hardwareAccelerated="false"
removed this line from manifests and the issue resolved for me.
I saw nothing wrong with your code, but if it couldn't worked. try to add this:
app:cardCornerRadius="#dimen/margin_small"
app:cardElevation="#dimen/margin_small"
app:cardUseCompatPadding="true"
It worked well for me. And make sure you're runing above API 21.
Try this :
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
card_view:cardCornerRadius="4dp">
</android.support.v7.widget.CardView>
reference link : check here
try it into style.xml
<item name="cardCornerRadius">9dp</item>
or simply put this line in your card view XML
app:cardCornerRadius="9dp"
Try this
<android.support.v7.widget.CardView
...
card_view:cardCornerRadius="20dp">
</android.support.v7.widget.CardView>
Perhaps 6dp radius is not noticable. :)
Suggestion
You need not to make many namespaces, you can use app for every attribute.
Just use this
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="20dp"

Simple UI - how to?

Using Android studio 3.1, and I have a strange problem, I can't edit my UI,
I enter the content_main.xml, using the design tab, blueprint, anything i drag to the blueprint is not appearing, I use the infer constraints, still not helping
this is my XML code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/app_bar_main">
<EditText
android:id="#+id/editText5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_editor_absoluteX="53dp"
tools:layout_editor_absoluteY="168dp" />
</android.support.constraint.ConstraintLayout>
I would't recommand using the UI designer, you don't get the feeling of what you are really doing with it. You should learn how to directly edit the XML file, this isn't really harder and at least you know what you are doing.
You must drag the widget to the component tree
ver imagen

How to disable Segmented control in Android?

Can any one please tell me, how to disable segmentedcontrol in android.
I have been using Foursquared library.
The link for library is given below.
You can do one thing for that.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<SegmentedButton
android:id="#+id/login_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
/>
<Layout
android:id="#+id/transperent_fragment"
android:name="com.test.transperentFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/body_texture"
android:alpha="0.2"
android:clickable="true"/>
</RelativeLayout>
Hope this helps you..:)

How to make FloatingButton stick to the bottom of WebView inside CoordinatorLayout?

I need to make FloatingActionButton always stick to the bottom of my fragment where I display WebView. The problem is that the button in my current XML is cut in half and I can't manage to fix it. Here is my layout.
<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:background="#color/colorBackgroundWhite"
tools:context=".fragments.CpuComparisionFragment">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="#+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/button_compare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginBottom="#dimen/fb_margin_16dp"
android:layout_marginEnd="#dimen/fb_margin_16dp"
android:alpha="0.7"
android:src="#drawable/ic_compare" />
</android.support.design.widget.CoordinatorLayout>
</FrameLayout>
What am i doing wrong? Any ideas how to fix this? Here is screenshot how my app looks now.
It seems the android version installed on the device you're testing your app on doesn't support some of your xml attributes. Anyways, replace the FAB code with the below snippet. I hope it work for you.
<android.support.design.widget.FloatingActionButton
android:id="#+id/button_compare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginBottom="#dimen/fb_margin_16dp"
android:layout_marginEnd="#dimen/fb_margin_16dp"
android:alpha="0.7"
app:layout_anchorGravity="bottom|right|end"
android:src="#drawable/ic_compare" />
Try to add android:fitsSystemWindows="true" to your FrameLayout .

Categories

Resources