Custom notification layout does not cover the entire width

I am trying to create my own NotificationManager layout, here is my layout file

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layoutnotification" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="3dp" android:background="@color/btn_bg_blue"> <ImageView android:id="@+id/image" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_height= "50dp" android:layout_width= "50dp" /> <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/image" style="@style/NotificationTitle" /> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/image" android:layout_below="@id/title" style="@style/NotificationText" /> </RelativeLayout> 

currently the notification appears as follows, but the problem is that the notification layout does not cover the entire width (on the right side), although I set layout_width to fill_parent , so I want the blue color to cover the entire width.

enter image description here

+4
source share
4 answers

Remove android:padding="3dp" . It pushes a background color of 3 pixels inward. If you need these three pixels, replace it with android:layout_marginRight="3dp" .

0
source

If you remove all paddings and fields in your layout elements, I assume that there is a chance that you will be able to see this gap. I sometimes noticed this on my HTC Desire. However, I also noticed that if I highlighted and then highlighted an event with a trackball (available in Desire) or with navigation keys, the gap will suddenly disappear. I can’t tell you why this behavior is, but this is what I experienced in the notification panel.

Just highlight and then highlight your notification and see if there is any difference.

0
source

I saw a lot of customizable notification layouts, some of them solve this problem using a transparent background, some of them make the same space on the left, complementing it to make it the center. I do not believe that there is a solution for this. Good luck.

0
source

I also had a problem, but now it is fixed. Just test your application on a real Android 2.3 device. good luck :)

0
source

Source: https://habr.com/ru/post/1401186/


All Articles