I am making a calendar. Each day is a textview with a number denoting the day of the month.
I'd like to overlay another view which signals that there is an event on that date. See below image or think about how the google calendar app looks. How do I do this?
One way is to make the two textview inside a Relative Layout or a Frame Layout. You can look at this for reference.
You could use a TableLayout to store the TextViews in rows and colums.
A possible way of marking a special day would be changing the background resource of the specific cell with one that has a marking on it, that does not overlap with the number.
If you want more fancy stuff, you could write your custom View subclassing TextView, which handles its onDraw calls and everything else.
As far as I know you can use a RelativeLayout to overlap views.
You can try setting left drawable (android:drawableLeft="") to the TextView. OR, you can use some transparent background images with indicators drawn in top-left.
Related
What I'd like to do is create a grid layout that has multiple live components. I'm trying to implement this layout, and am struggling to figure out the best way of doing it.
The 4 main elements of the grid layout:
Imageview (the green bar). It changes colours to green/ red/ or yellow, depending on the delay.
Textview (the title). The title changes based on an update call. It's the recommended title.
Textview (Delay). Will be a string with the delay status (either No delay or 30 Minutes)
Imageview (background for delay text). Will never change.
After reading about this on StackOverflow, an embedded grid layout seems to be the best choice, but I haven't seen a good way of incorporating different elements (that are set every new "Update"/ pageload) into a Grid Layout without having multiple views set for each element.
Here is the picture I want to implement (http://imgur.com/8TrFvl8)
Perhaps consider using a recycler view instead
So here is my problem. I've spent couple of days on this and didn't get anywhere. I've tried every layout possible, but it just doesn't seem to work.
Basically, I have a map of a floor and I want to make it so when you click on different parts of that floor, a new activity or a dialog box shows up. I want this to scale for all the devices. Why is this so difficult in Android? I would think that putting buttons on top of an image would be easy and made sure that it wouldn't move like in HTML.
I have been looking into Surface View, but wasn't sure if that's the best way to go? I can get the coordinates of the objects on the floor, would that help?
I want to implement this inside of an fragment. Thanks!
One possible solution could be to have a RelativeLayout as the base layout of your 'Floor Map' fragment, with the floor image set as its background.
Then you could add buttons or any other views to the Relativelayout at the coordinates of the objects.
If you already know how many features the floor will have, you could add the buttons statically, otherwise, loop through your array of features to add them dynamically.
There is compound drawable option in TextView to avoid using a parent ViewGroup and an ImageView next to TextView. Which is neat and faster in performance as said by lint. I'm trying to do something similar. A TextView with 2 texts inside, one aligned to left, one aligned to write. Sounds strange but it will only allowed for single line TextView.
And to do that, I can extend TextView and set its gravity to right side. And inside onDraw let the super class draw on right side, and then draw text on left side.
Problem is, I'm not really sure about all this. My question is, will there be a big performance difference ? I dont have any slower device to test. I will be using this TextView inside an item layout of GridView, Item layout already have many views, it would be nice if I could merge some views to one. But again, will there be a performance difference, like noticeable by user ? And if there will be, the approach I will be using by extending the TextView, is there any problem or I should try some other way ?
Thank you
From what I have read I would imagine that you are using a custom adapter for your GridView?
If so, cant you just use TableRow and insert 2 TextViews inside that with each layout weight set to 1. Then you will have 2 columns in one row?
Just an idea.
Is there any way position views relative to each other like you can with Android layouts?
Example: You have two UILabels that are dynamically set to strings of variable length, one above the other, and you want the bottom label to appear directly below the last line of the top label, regardless of how many lines the top label ends up having.
Another example: Same situation as above, but one of the labels is sometimes hidden. You want the resulting label(s) to be centered vertically in the parent, regardless of whether it's one label or two labels.
Android's Linear Layout and Relative Layout make this very easy to do, but I can't figure out how to do this is iOS. Can it be done?
You will be able to do this using AutoLayout in iOS6. For an application that should run in iOS before 6.0, you have to do it by yourself, but this is not very complicated.
Actually I have implemented a class to do this (that's a long time ago, I hope it still works, but there is no reason not to). This OHStackView class is a subclass of UIView that automatically layout its subviews horizontally or vertically to stack or align them.
You can ask OHStackView to stack its subviews horizontally or vertically (one above the other, etc), or align their top/bottom/left/right borders or their centers, and even specify a padding between each subviews. Each time one of the subview changes its frame or size, OHStackView will automatically relayout all depending views to realign everything.
(E.g with your two UILabels, a simple call to sizeToFit on your labels to make them adjust their size to their content will relayout everything around automagically)
There is an example project provided so feel free to test it.
Note: IIRC, my subclass does not take the "hidden" property of the subviews into account. But you can easily add support to this behavior by adding a condition like if (v.hidden) continue; in the for loop of its layoutSubview implementation to only take non-hidden views into account in the layout algorithm.
HTH
I've been searching if it's possible for a long time. As far as i can tell, it's not possible for now. I don't remember where i read this,but it will be possible with ios6. Instead of using Android's Linear Layout,you can use sizeWithFont method to detect size of your UILabel,then you can set their frame to position them.First,you need to set their text of course to find their size according to their font family. Another thing you can use is sizeToFit method. Unfortunately,i don't know how to use it. You can give a shot,though. At that time,i found this.Maybe ,you can use it https://github.com/scalessec/CSLinearLayoutView
Good evening,
I am trying to wrap my text around an image view like the question is asking here:
Textview wrap around View
in landscape.
but I wish to not do it in HTML / CSS. plus, that question is 2 years old. I am hoping someone has figured out a work around with this.
Also, I wish to keep my portrait view the way it is with the img view under the text view i.e. no wrapping.
Can anyone help me?
A work around I can think off the top of my head and from previous issues with TextView formatting, the best way is to have, say, a RelativeLayout, and just place 3 separate Views inside of it. It will represent the TextView that is right next to the image, the ImageView itself next to the text, and then the last TextView under the first text, but with the layout_width="match_parent". There is no other way to do this with the TextView or ImageView otherwise.
EDIT:
The only other workaround I believe you can do if you are so intent on using 1 TextView, I would suggest using SpannableStringBuilder with SpannableString. I didn't originally give you that as an option for a specific reason. If you go back to that link you posted on your question, one of the answers say they found an answer. I believe that person linked to a good resource, but they are wrong for what your needs are. When using SpannableStringBuilder, you are essentially creating a string that can have potentially many different version of a single string into one, like 3 different colors on a single string, or strings with 3 different sizes, all in one TextView. Like what you need.
Now the link talks about putting an image and having the text wrap around it nicely, but its not that simple, and that example isn't what you need. What you could do to provide it all in one TextView is to add line breaks after the first few lines where you know the image will be to the right, and then not do so after the image. But the thing is it still needs to go in a RelativeLayout. But instead of two TextViews you only need one. Just place the TextView at the top left of whatever the parent is and the ImageView to the top right of whatever the parent is. This simulates a floating element. But I think doing it that way is more trouble than its worth. It really is because you have to do calculations to figure out where to put the line breaks, etc. You are better off using two TextViews in which to make it look like you need. So in my opinion, DO NOT USE SpannableStringBuilder, but if you do not mind trying to figure out all that spacing, that does give you what you need with a single TextView.