Image is not shown in the CardView - android

Although the preview shows the image but when I run the application on the device, the image is not shown in the card view.
XML
<com.google.android.material.card.MaterialCardView
android:id="#+id/CollegesCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ImportantDatesCard"
android:layout_alignParentStart="true"
android:layout_marginStart="15dp"
android:layout_marginTop="13dp"
android:elevation="10dp"
android:padding="10dp"
android:background="#drawable/campus"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:stateListAnimator="#drawable/lift_on_touch">
<RelativeLayout
android:layout_width="170dp"
android:layout_height="170dp"
android:layout_gravity="center">
<TextView
android:id="#+id/COLLEGES"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:fontFamily="serif-monospace"
android:text="COLLEGES"
android:textColor="#000"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/Content"
android:layout_width="102dp"
android:layout_height="107dp"
android:layout_below="#+id/COLLEGES"
android:layout_marginStart="1dp"
android:layout_marginTop="14dp"
android:text="Take Admission in Top Colleges in your Location"
android:textColor="#200094"
android:textSize="15sp" />
<ImageView
android:id="#+id/CAMPUSIMAGE"
android:layout_width="65dp"
android:layout_height="73dp"
android:layout_below="#+id/COLLEGES"
android:layout_alignStart="#+id/Content"
android:layout_marginStart="101dp"
android:layout_marginTop="2dp"
tools:srcCompat="#drawable/campus" />
<ImageView
android:layout_width="54dp"
android:layout_height="38dp"
android:layout_below="#id/CAMPUSIMAGE"
android:layout_alignStart="#+id/CAMPUSIMAGE"
android:layout_alignParentEnd="true"
android:layout_marginStart="7dp"
android:layout_marginTop="13dp"
android:layout_marginEnd="14dp"
tools:srcCompat="#drawable/ic_arrow_forward_black_24dp"
android:scaleType="centerCrop"/>
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
[This is the image of the snapshot from virtual device.1[This is the image of the preview]2
I have attached the images of screenshot of the preview and the application running on a device. I have no idea why the image is not shown.
Image type is .png and it is been added from the drawable folder.

I changed some attributes of the 3 views, try it:
<com.google.android.material.card.MaterialCardView
android:id="#+id/CollegesCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ImportantDatesCard"
android:layout_alignParentStart="true"
android:layout_marginStart="15dp"
android:layout_marginTop="13dp"
android:elevation="10dp"
android:padding="10dp"
android:background="#drawable/campus"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:stateListAnimator="#drawable/lift_on_touch">
<RelativeLayout
android:layout_width="170dp"
android:layout_height="170dp"
android:layout_gravity="center">
<TextView
android:id="#+id/COLLEGES"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:fontFamily="serif-monospace"
android:text="COLLEGES"
android:textColor="#000"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/Content"
android:layout_width="102dp"
android:layout_height="107dp"
android:layout_below="#+id/COLLEGES"
android:layout_marginStart="1dp"
android:layout_marginTop="14dp"
android:text="Take Admission in Top Colleges in your Location"
android:textColor="#200094"
android:textSize="15sp" />
<ImageView
android:id="#+id/CAMPUSIMAGE"
android:layout_width="65dp"
android:layout_height="73dp"
android:layout_below="#+id/COLLEGES"
android:layout_alignParentEnd="true"
android:layout_toEndOf="#+id/Content"
android:layout_marginTop="2dp"
tools:srcCompat="#drawable/campus" />
<ImageView
android:layout_width="54dp"
android:layout_height="38dp"
android:layout_below="#id/CAMPUSIMAGE"
android:layout_alignParentEnd="true"
android:layout_toEndOf="#+id/Content"
android:layout_marginStart="7dp"
android:layout_marginTop="13dp"
android:layout_marginEnd="14dp"
tools:srcCompat="#drawable/ic_arrow_forward_black_24dp"
android:scaleType="centerCrop"/>
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>

Related

View with rotation property get cuts off

I have to create three CardView like structure as shown in the below image. For that, I am currently using
Constraintlayout but facing multiple issues i.e, clipping issue.
There is no usecase of swipe animation or anything like that.
Is there anything that I am missing here.Any help will be appreciated.
Here is my code:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:id="#+id/card_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:rotation="-20"
android:layout_marginTop="#dimen/dimen_12"
android:layout_marginStart="#dimen/dimen_25"
app:cardCornerRadius="#dimen/dimen_8"
app:cardElevation="#dimen/dimen_1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:id="#+id/rl_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/top_colored_gradient_dark"
android:padding="#dimen/dimen_12">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/img_one"
android:layout_width="72dp"
android:layout_height="72dp"
android:src="#drawable/blue_social" />
<TextView
android:id="#+id/txt_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/img_one"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/dimen_15"
android:textColor="#313131"
android:textSize="#dimen/dimen_14sp"
tools:text="Title Here" />
<TextView
android:id="#+id/txt_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txt_name"
android:layout_centerHorizontal="true"
android:textColor="#color/light_text_color"
android:textSize="#dimen/dimen_11sp"
tools:text="Date" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/card_second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardElevation="#dimen/dimen_2"
app:cardUseCompatPadding="true"
app:cardCornerRadius="#dimen/dimen_8"
android:layout_marginEnd="#dimen/dimen_15"
app:layout_constraintEnd_toStartOf="#id/card_third"
app:layout_constraintStart_toEndOf="#id/card_one"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:id="#+id/rl_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/top_colored_gradient_dark"
android:padding="#dimen/dimen_12">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/img_two"
android:layout_width="72dp"
android:layout_height="72dp"
android:src="#drawable/blue_social" />
<TextView
android:id="#+id/txt_name_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/img_two"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/dimen_15"
android:textColor="#313131"
android:textSize="#dimen/dimen_14sp"
tools:text="Title Here" />
<TextView
android:id="#+id/txt_date_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txt_name_two"
android:layout_centerHorizontal="true"
android:textColor="#color/light_text_color"
android:textSize="#dimen/dimen_11sp"
tools:text="Date" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/card_third"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardElevation="#dimen/dimen_1"
app:cardCornerRadius="#dimen/dimen_8"
android:layout_marginTop="#dimen/dimen_8"
android:rotation="20"
app:cardUseCompatPadding="true"
app:layout_constraintStart_toEndOf="#id/card_second"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:id="#+id/rl_third"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/top_colored_gradient_dark"
android:padding="#dimen/dimen_12">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/img_third"
android:layout_width="72dp"
android:layout_height="72dp"
android:src="#drawable/blue_social" />
<TextView
android:id="#+id/txt_name_third"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/img_third"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/dimen_15"
android:textColor="#313131"
android:textSize="#dimen/dimen_14sp"
tools:text="Title Here" />
<TextView
android:id="#+id/txt_date_third"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txt_name_third"
android:layout_centerHorizontal="true"
android:textColor="#color/light_text_color"
android:textSize="#dimen/dimen_11sp"
tools:text="Date" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
You can use FrameLayout instead of constraint to stack Views like in the Image.

Android TransactionTooLargeException with NotificationManager

I am getting TransactionTooLargeException exception when sending a notification with a custom layout.
java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 588636 bytes
at android.app.NotificationManager.notifyAsUser(NotificationManager.java:380)
at android.app.NotificationManager.notify(NotificationManager.java:286)
at android.app.NotificationManager.notify(NotificationManager.java:270)
It's probably because of the bitmaps in the layout, but it's not happening on all of the devices, so I don't want to reduce or remove those bitmaps, is there anything else I can do?
This is my layout
<?xml version="1.0" encoding="utf-8"?>
<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="64dp"
android:background="#color/colorPrimary"
android:orientation="horizontal">
<ImageView
android:layout_margin="0dp"
android:id="#+id/userImage"
android:layout_width="64dp"
android:layout_height="64dp"
tools:src="#tools:sample/avatars" />
<LinearLayout
android:layout_marginStart="5dp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:maxLines="1"
android:id="#+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/yellow"
android:textSize="20sp"
android:textStyle="bold"
tools:text="#tools:sample/full_names" />
<TextView
android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:textColor="#color/yellow"
android:textStyle="bold"
tools:text="0:25" />
</LinearLayout>
<ImageView
android:id="#+id/muteButton"
android:padding="1dp"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:background="#drawable/circle2"
android:src="#drawable/mute_icon"
android:tint="#color/black" />
<ImageView
android:id="#+id/micButton"
android:padding="1dp"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:background="#drawable/circle2"
android:src="#drawable/speaker"
android:tint="#color/black" />
<ImageView
android:id="#+id/endCallButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:background="#drawable/circle2"
android:src="#mipmap/call_end_icon" />
<ImageView
android:visibility="gone"
android:id="#+id/answerButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:background="#drawable/circle2"
android:src="#mipmap/call_icon" />
<FrameLayout
android:layout_width="8dp"
android:layout_height="0dp"/>
</LinearLayout>
The only bitmap that I upload dynamically is userImage, I am using Glide to load it and I provide a fixed size of 64x64 DP converted to device pixels.

Hello friends how achieve bottom media controller layout?

Hello friends i am beginner in android i want know how to achieve this type layout the image which shown below please help me i trying achieve this type of layout
It is very simple layout FYI
It can be done with any type of parent layout Constraint, Relative and
even with Linear
I will share a Relative one example. Use your own drawables and assests.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayoutMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/black"
android:padding="4dp">
<TextView
android:id="#+id/textViewSongTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginStart="24dp"
android:layout_marginEnd="10dp"
android:layout_toStartOf="#+id/buttonBackward"
android:ellipsize="end"
android:maxLines="1"
android:padding="2dp"
android:text="Song Name - [details]"
android:textColor="#android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textViewArtistName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textViewSongTitle"
android:layout_alignParentStart="true"
android:layout_marginStart="24dp"
android:layout_marginEnd="10dp"
android:layout_toStartOf="#+id/buttonBackward"
android:padding="2dp"
android:text="Singer Name"
android:textColor="#android:color/white"
android:textSize="12sp" />
<Button
android:id="#+id/buttonForward"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="8dp"
android:background="#android:color/holo_green_dark"
android:gravity="center"
android:text="F"
android:textColor="#android:color/white" />
<Button
android:id="#+id/buttonPlayAndStop"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginEnd="8dp"
android:layout_toStartOf="#id/buttonForward"
android:background="#android:color/holo_green_dark"
android:gravity="center"
android:text="PS"
android:textColor="#android:color/white" />
<Button
android:id="#+id/buttonBackward"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_marginEnd="8dp"
android:layout_toStartOf="#id/buttonPlayAndStop"
android:background="#android:color/holo_green_dark"
android:gravity="center"
android:text="B"
android:textColor="#android:color/white" />
</RelativeLayout>

Android Studio Background color not displaying

I have worked on a small app where I designed multiple pages. however the first page is not displaying the correct background color when I run the app , although I'm 100% sure the color is amended. below you see the codes of xml.
also even the action bar is still there although I removed and used no action bar them.
what seems to be the issue ?
note: Android studio updated
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:background="#243447"
tools:context="#243447">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="97dp"
android:fontFamily="sans-serif-smallcaps"
android:text="Choose your focus"
android:textColor="#android:color/holo_red_light"
android:textSize="24sp" />
<RelativeLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="413dp"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="0dp"
android:layout_marginBottom="0dp"
tools:background="#243447">
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/button2"
android:layout_alignTop="#+id/button5"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:layout_marginBottom="195dp"
android:background="#243447"
android:fontFamily="sans-serif-smallcaps"
android:hapticFeedbackEnabled="false"
android:shadowColor="#android:color/background_dark"
android:text="Work"
android:textAllCaps="false"
android:textColor="#android:color/holo_red_light"
android:textColorHighlight="#android:color/darker_gray"
android:textSize="14sp" />
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/button4"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="61dp"
android:layout_marginBottom="195dp"
android:background="#243447"
android:fontFamily="sans-serif-smallcaps"
android:hapticFeedbackEnabled="false"
android:shadowColor="#android:color/background_dark"
android:text="Community"
android:textAllCaps="false"
android:textColor="#android:color/holo_red_light"
android:textColorHighlight="#android:color/darker_gray"
android:textSize="14sp" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/button2"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="0dp"
android:background="#243447"
android:fontFamily="sans-serif-smallcaps"
android:hapticFeedbackEnabled="false"
android:shadowColor="#android:color/background_dark"
android:text="Relgion"
android:textAllCaps="false"
android:textColor="#android:color/holo_red_light"
android:textColorHighlight="#android:color/darker_gray"
android:textSize="14sp" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="61dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:background="#243447"
android:fontFamily="sans-serif-smallcaps"
android:hapticFeedbackEnabled="false"
android:shadowColor="#android:color/background_light"
android:text="Health"
android:textAllCaps="false"
android:textColor="#android:color/holo_red_light"
android:textColorHighlight="#android:color/darker_gray"
android:textSize="14sp" />
</RelativeLayout>
</RelativeLayout>
You are using tools:background="#243447" the keyword tools is only for the screen preview in android studio.
If you would like to have the background color in your app you need to use the keyword android
android:background="#243447"
Try to use
android:background="#243447"
instead of
tools:background="#243447"
and you have to put your class name in
tools:context=".ActivityName"

highlighting items of recyclerView

I want to highlight the selected list item totally, not only background color but the whole list item should have same color.
This is the one without highlighting
I want the output as this was
I am getting just the background color. I have used this code
view.setBackgroundResource(R.color.white);
I am getting like this as output
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/alert_Item"
android:layout_marginTop="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:background="#drawable/list_corners"
>
<ImageView
android:id="#+id/imageView3"
android:layout_width="8dp"
android:layout_height="13dp"
/>
<TextView
android:id="#+id/date"
android:layout_width="108dp"
android:layout_height="13dp"
android:text="member name"
android:textSize="10sp"
android:textColor="#color/textColorPrimary"/>
<TextView
android:id="#+id/memberName"
android:layout_width="98dp"
android:layout_height="13dp"
android:layout_alignParentRight="true"
android:text="member name"
android:textAlignment="textEnd"
android:textSize="10sp"
android:textColor="#color/textColorPrimary"/>
<TextView
android:id="#+id/alertId"
android:layout_width="132dp"
android:layout_height="15dp"
android:text="alert id"
android:textSize="12sp"
android:textColor="#color/textColorPrimary"/>
<TextView
android:id="#+id/alertName"
android:layout_width="72dp"
android:layout_height="13dp"
android:layout_alignBaseline="#+id/alertId"
android:layout_alignParentRight="true"
android:layout_marginTop="2dp"
android:text="alert name"
android:textAlignment="textEnd"
android:textSize="10sp"
android:textColor="#color/textColorPrimary"/>
</RelativeLayout>

Categories

Resources