cardView shadow elevation dosn't work well android studio - java

when i try to add a shadow to my cardView .. it works but only with a small width of card like below
so when i make the widht equal to 272dp and that what i want, the corners have no shadow like so
and this is my code! can anybody help?! & thank you too much :)
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:clipToPadding="false"
android:clipChildren="false"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="#+id/textView7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="17dp"
android:text="Available in" />
<androidx.cardview.widget.CardView
android:layout_width="160dp"
android:layout_height="58dp"
android:layout_gravity="center"
android:cardElevation="10dp"
android:layout_margin="8dp"
/>
</LinearLayout>
</LinearLayout>

Related

There is a jerk when I set visibility GONE for this button

I am using android:animateLayoutChanges="true"
here I am sharing my card view layout :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="280dp"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:id="#+id/cvRegisteredPharmacy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginBottom="30dp"
app:cardBackgroundColor="#color/colorAccent"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical">
<ImageView
android:id="#+id/ivPharmacy"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_weight="0.25"
android:background="#color/colorWhite" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:id="#+id/tvPharmacyName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Pharmacy Name"
android:textColor="#color/colorWhite"
android:textSize="16sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RatingBar
android:id="#+id/rbPharmacyRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
style="?android:attr/ratingBarStyleSmall"
android:rating="3.5"
android:progressTint="#color/colorPrimary"
android:progressBackgroundTint="#color/colorGrey" />
<TextView
android:id="#+id/tvPharmacyInfo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:text="3.5"
android:textColor="#color/colorWhite"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:id="#+id/tvPharmacyAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Pharmacy Address, 1/2 Main St NW, Monteral, QC"
android:textColor="#color/colorWhite"
android:textSize="14sp" />
</LinearLayout>
<Button
android:id="#+id/btnSelectPharmacy"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="15dp"
android:background="#drawable/btn_bg_white"
android:text="Select Pharmacy"
android:textColor="#color/colorAccent"
android:visibility="gone" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
Here is the complete layout that I've made
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.PharmacyMapActivity">
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvPharmaciesList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
Also, I am sharing the simple code where I am setting visibility of this button :
if (holder.btnSelectPharmacy.getVisibility() == View.VISIBLE){
holder.btnSelectPharmacy.setVisibility(View.GONE);
} else {
holder.btnSelectPharmacy.setVisibility(View.VISIBLE);
}
I've tried many solutions so far including view animation, Object animator, Expandable layout (through library) but no luck so far!
looking forward for your suggestions.
I've a workaround for this to lift the card up but then I want to make my card expanded from upside exactly as like as in the above picture.
While using automatic layout animation on the child node, the result will be, that the parent node just snaps to layout_alignParentBottom & wrap_content once the child node is View.GONE.
Combining two animations could make it less jerky. I mean, the CardView would need it's height animated; either synchronously or once the child node is View.GONE. Actually, when animating the child node to height 0dp, this would also animate the parent node's height, since it's wrap_content; setting a static value for the height would also prevent it from snapping alike that. Also animating to View.INVISBLE and then animating it's height would prevent the parent node from snapping. Sorry for not providing a ready-made solution, but explaining why it behaves alike that and how it might work is still better than no answer.

How to slow down the Scrolling speed of Recyclerview both in vertically and horizontally?

In My Android project I am using RecyclerView inside one layout. Here is the code given below-
<RelativeLayout 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"
xmlns:custom="http://schemas.android.com/apk/res-auto"
tools:context=".ui.reader.pageview.PageViewFragment">
<TextView
android:id="#+id/tv_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView
android:overScrollMode="never"
android:id="#+id/rv_page_view"
android:layout_below="#id/pb"
android:layout_above="#+id/ll_page_controller_bottom"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
<LinearLayout
android:background="#color/colorWhite"
android:orientation="vertical"
android:id="#+id/ll_page_controller_bottom"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#DADADA" />
<org.adw.library.widgets.discreteseekbar.DiscreteSeekBar
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:id="#+id/seek_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:dsb_indicatorColor="#color/colorOrange"
app:dsb_trackColor="#color/colorOrange"
app:dsb_progressColor="#color/colorOrange"
app:dsb_rippleColor="#color/colorGray"
app:dsb_min="0"
app:dsb_max="100"/>
<TextView
android:layout_marginTop="-10dp"
android:layout_marginBottom="5dp"
android:text="1"
android:id="#+id/tv_page_number"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<View
android:layout_below="#id/pb"
android:layout_above="#id/ll_page_controller_bottom"
android:id="#+id/view_touch"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<RelativeLayout
android:visibility="invisible"
android:id="#+id/rl_settings"
android:layout_alignParentEnd="true"
android:layout_below="#id/pb"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<include layout="#layout/reader_settings"/>
</RelativeLayout>
<TextView
android:layout_margin="10dp"
android:layout_below="#id/pb"
android:id="#+id/tv_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="16sp"
android:visibility="invisible"
android:layout_above="#id/ll_page_controller_bottom"/>
</RelativeLayout>
Now, for rendering a lot of data when the users scrolls too much fast the screen got hanged. So, I want to slow down the speed of the scrolling.
I have tried the following solution-
How can i control the scrolling speed of recyclerView.smoothScrollToPosition(position)
It works well with horizontal scrolling but when I switch to vertical view then It doesn't work.
Is there any way to solve this?

Merging Multiple TextViews onto a Bitmap - should i use canvas?

I have found that you can add or merge textviews onto a bitmap. I have 4 textviews that I would like to merge onto the top of the image.
Here is a screenshot of what I would like to achieve (although at the minute this is textviews at the top separate to the image):
the image is below the textviews. Image header in top right is for what image No it is
So what I am trying to do is once I click the send button it "prints" or merges these Textviews onto the image bitmap below so that I can then save or send the image(with the textviews in it) as one file to my server/device.
So far I have used Canvas.draw() method although it seems to overwrite each other and I am trying to keep the same layout as the screenshot.
Can anyone help?
Try this...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottomLayID"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2"
android:padding="8dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Detail work order"
android:textStyle="bold"
android:gravity="center"
android:layout_weight="0.5"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Image"
android:textStyle="bold"
android:gravity="center"
android:layout_weight="1.5"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2"
android:padding="8dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:gravity="center"
android:layout_weight="0.5"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:gravity="center"
android:layout_weight="1.5"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/bottomLayID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true"
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Open Camera"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send Image"
android:background="#99d72e"/>
</LinearLayout>
</RelativeLayout>
Give background as transparent color and border to textviews.
You can set bitmap to imageview by
ImageView mImg;
mImg = (ImageView) findViewById(R.id.(your xml img id));
mImg.setImageBitmap(img);

How to center in ScrollView and LinearLayout

Please have a look at the following code
<ScrollView 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"
tools:context=".DisplayResult" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:id="#+id/zodiac1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/aries"
/>
<TextView
android:id="#+id/orTxt"
android:text="Or"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="#+id/zodiac2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/gemini"
/>
</LinearLayout>
</ScrollView>
I need to center everything inside the LinearLayout. I must use scrollview because when the app is 100% done, there will be lot of information which cannot be viewed by a single glance, without scrolling. How can make these center? Please help!
UPDATE
use any layout inside the scroll, no prob. But I need those elements to be in the same order (one after another) and centered.
you need to set gravity as centered for linear layout
< LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal" >
This one worked for me:
<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:gravity="center">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
Try using layout_gravity on your LinearLayout to center_horizontal:
<LinearLayout
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_height="wrap_content"
android:orientation="horizontal"/>
<ScrollView 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"
tools:context=".DisplayResult"
scrollbars="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal">
<ImageView
android:id="#+id/zodiac1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/aries"
/>
<TextView
android:id="#+id/orTxt"
android:text="Or"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="#+id/zodiac2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/gemini"
/>
</LinearLayout>
</ScrollView>
#If you want to Linear layout in a center you need to write android:gravity="center_horizontal" in your linear layout.

Android Wear: Layout is not displaying properly in Emulator

I'm developing an Android smart watch application. The initial screen appears fine. But, when I go to next screen, the upper part pops up with the name of project something like this. In the below image, Watch is the name of the project.
I want to see the entire screen instead of white space which contains project's name. Does anyone know how to solve it and why is it appearing?
My XML file is
<?xml version="1.0" encoding="utf-8"?>
<android.support.wear.widget.BoxInsetLayout 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"
tools:deviceIds="wear">
<LinearLayout
android:id="#+id/mainContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/black"
android:weightSum="1"
tools:ignore="UselessParent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<LinearLayout
android:id="#+id/sign_up_top_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:layout_marginTop="15dp">
<TextView
android:id="#+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="5dp"
android:textAlignment="center"
android:textSize="18sp"
android:text="#string/text"
android:background="#color/black"
android:textColor="#color/white"
android:fontFamily="Century-Gothic.ttf" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="18dp"
android:layout_height="19dp"
android:layout_toRightOf="#+id/text"
android:src="#drawable/fingerprint" />
</LinearLayout>
<Button
android:layout_marginTop="10dp"
android:id="#+id/button"
android:background ="#drawable/roundedbutton"
android:text="#string/button_text"
android:layout_width="108dp"
android:textAlignment="center"
android:drawablePadding="20dp"
android:layout_gravity="center"
android:textColor="#color/white"
android:layout_height="75dp"
android:layout_weight="0.34" />
</LinearLayout>
</android.support.wear.widget.BoxInsetLayout>
Use a BoxInsetLayout for your root layout:
This class applies the required window insets depending on the screen
shape and lets you easily align views on the center or near the edges
of the screen.
And I would highly recommend you to read through this tutorial.
Edit 2:
You need to use:
android.support.wearable.view.BoxInsetLayout
not:
android.support.wear.widget.BoxInsetLayout
and add to the mainContainer:
app:layout_box="all"
<android.support.wearable.view.BoxInsetLayout
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"
tools:deviceIds="wear">
<LinearLayout
app:layout_box="all"
android:id="#+id/mainContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/black"
android:weightSum="1"
tools:ignore="UselessParent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
The answer to the question was simple. I figured out after one day. I changed my theme from Theme.AppCompat.Light to Theme.AppCompat.Light.NoActionBar in Manifest file. The program name bar disappeared.

Categories