custom notification layout doesn't cover the whole width - android

i am trying to create a custom layout of NotificationManager , 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 follow , but the problem is the notification layout doesn't cover the whole width (on right side) even though i have set layout_width to fill_parent so i want the blue color covers the whole width.

Remove android:padding="3dp". It's pushing the background color 3 pixels inward. If you need those three pixels, replace it with android:layout_marginRight="3dp".

If you remove all the paddings and margins in your layout elements, i guess there's still possibility that you can see this gap. I've noticed this sometimes on my HTC Desire too. However, I've also noticed that if I highlight and then unhighlight the event with trackball (available in Desire) or with navigation keys, the gap suddenly goes away. I can't tell you why this behavior is, but it is something I've experienced in notification bar too.
Just highlight and then unhighlight your notification and see if there's any difference.

I saw many custom notification layouts, some they solve this problem by using transparent background, some they do the same gap in the left by padding to make it center. I don't believe there is a solution for it. Good luck

I was also facing the same problem but now its fixed. Just check your app on real device of android 2.3.
good luck :)

Related

xPlace EditText over fixed points on background image for different resulution

I'm building layers in Android, for that I'm loading an background image into ImageView with a small mini black boxes drawn over it, like placeholders.
I was wonder how can I set some EditText over those small mini points on the image,you cant see them but suppose I have to black box'x over the bg image and I want to place over them my text1,text2. I tried using RelativeLayout and using fixed padding but when changing the screen size or orientation it get messy, I read that the best thing is to place them on run time by checking the screen resolution and calculating the right sizes for each EditText, but it is to much work I think.
<?xml version="1.0" encoding="utf-8"?>
<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" >
<RelativeLayout
android:id="#+id/background_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/bg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/bg" />
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"/>
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"/>
</RelativeLayout>
</RelativeLayout>
This is the Image, and I want to put some text on the black boxes of the result and the team.
What options do I have?
There is lot of device size variation in Android you can't get perfection by doing this, I would recommend you to use plain background of image and take that small mini boxes as different image and set it as a EditText background.
other wise you have to manually set the padding and margin for every devices in which you getting differences.
I hope this will help you.

android:layout_centerVerticle="true" not having an effect on my edit text

I have a edittext and a button in a relative layout. Here is the xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5sp" >
<Button
android:id="#+id/action_home_button"
android:layout_width="35sp"
android:layout_height="35sp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/home_button" />
<EditText
android:id="#+id/action_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/action_home_button"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="Some hint..."
android:textColor="#FFFFFF"
android:textColorHint="#DDDDDD" />
</RelativeLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="5sp"
android:layout_alignParentBottom="true"
android:background="#EC9D21" />
</RelativeLayout>
The problem is that the button is centered in the RelativeLayout just fine, but my EditText is aligned to the top of the layout. Is there anything that I'm missing? Thank you in advance.
Edit Above I updated my xml. I set this as a custom view of my action bar. But that should not make a difference, since the button has no problem aligning to center vertical. Thanx
Edit EditText should be aligned center vertical
The standard EditTexts in some themes seem to have some built in padding or margin around and/or under it. If you wish to eliminate this issue, then I would heavily suggest either using a nine patch, background color, or some other form of custom background.
Trying to set a negative bottom margin or something crazy might fix the issue for one standard EditText, but you have to be careful between Android versions as their EditTexts can have different themes and give rather unexpected behavior.
As for why the theme designers chose to have this gap underneath is beyond me. My best guess would be that is their way of "saving face" when the developer doesn't add a margin between vertically aligned EditTexts?
+1 for Uxonith. Changing the background seemed to do the trick eg. android:background="#000000". For me this works fine, because I had to change the background anyways, but if you need the standard edit text, this will not be a solution.

Ugly bug? First item in RelativeLayout cannot be centered

We try a simple thing. Display a TextView horizontally and vertically centered in a RelativeLayout.
This should be
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
Against all expectations the text appears top left here.
But now add a totally pointless LinearLayout to the whole thing:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- First item in a relative Layout cannot be centered -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
>
</LinearLayout>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
and tadaaaa! The text appears where we want him to. You cannot remove any of the lines in the LinearLayout without changing the location of the TextView. It seems RelativeLayout needs some items to be aligned against top/bottom and right/left before you can center any other item.
Similar problem ?
Problem description
I currently have a similar issue with a wrapping RelativeLayout holding a TextView that should be centered due to the use of android:layout_centerInParent="true".
Running my code on an API level 21 device or emulator shows the text properly centered.
However running the same code on API level 19 puts the text view at the top of the wrapping RelativeLayout instead of centered.
Example project
Just for the ease of following I created a sample project at https://github.com/hanscappelle/SO-16731025 Just check out this code from git and import in Android Studio and you should be able to run the code.
Visualisation
You can even test this issue using the design preview in Android Studio by just changing the SDK version for rendering.
Just open the file at layout/with_scrollview.xml and you should get a visualisation of it in the preview in Android Studio.
Using API level 21:
Same layout using API level 19:
Work around
Wrapping ScrollView
As a work around I discovered that removing the wrapping ScrollView solves the problem.
What didn't help
Dummy view
Adding a dummy LinearLayout (or any other view) in between like you suggested didn't resolve my problem.
The example project has this technique applied in the circle at the right of the screen.

Android: how to set two buttons in vertical linear layout to same width?

In my Android app I want to create a dialog window that contains an image on top, some info text in the middle, and two buttons below. These two buttons are within a linear layout with vertical orientation. Both sould be of the same width.
I have managed to create a similar layout as described, however, the button with the longer text on it becomes wider than the other one. In the attached picture, the lower button is a bit wider than the button above, as marked by the dotted red line.
The layout I use for this inner linear layout looks as follows:
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/close_dialog_button_ok"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/upload_dialog_ok"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip" />
<Button
android:id="#+id/close_dialog_button_cancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/upload_dialog_cancel"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip"
android:layout_marginBottom="5dip" />
</LinearLayout>
Any ideas what I am doing wrong here?
Thanks in advance for your help!
You forgot to set android:layout_marginLeft="10dip" on the second button
You will have to change the 'android:layout_width="fill_parent"' to something like '200dp' if you want them to be the same. As the app will make one of them longer due to the text inside being longer. So try setting both buttons to this:
android:layout_width="200dp"
They will then be the same and due to using 'dps', should still stay in proportion correctly on all screen sizes.

Button positioning issue in Relative Layout

I got a problem in a project with the following structure. On each emulator (also large screens) a button positioned within a simple relative layout using that code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/first_bg" >
<Button
android:id="#+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="202dp"
android:layout_marginRight="54dp"
android:background="#drawable/m_button"
android:text="#string/next" />
</RelativeLayout>
appears fine. BUT testing the app on Galaxy Note has shown that the button just flies away to some crazy positions. I used an emulator with similar configuration and the button appeared properly. I have no idea where the problem could be..
Have you tried to use a linearlayout instead?
With it you don't nedd to set the margin, just the position
It's based on the density-independent pixels (dp units), it'll show up at different positions on different phones.
http://developer.android.com/guide/practices/screens_support.html#density-independence

Categories

Resources