Implementing a different style text view - java

Please have a look at the following image.
This is a text view which I need in my next android app. However, I really don't know how to implement this kind of textview. I only know how to put a normal rectangle style textview. So, how can I achieve this? If textview is not possible, what are other options?

The simplest thing to do is to create an image (a 9patch would be perfect) and put your text over it.
I did a little image for you. Give it a try:
https://docs.google.com/file/d/0B-Ax5zr61_Dvb2QwcmtWUml1Q2s/edit?usp=sharing
Otherwise you can use a Layout that will wrap your TextView (with the rectangle background) and the image of the little triangle below.
You can also try to "paint" it (using Canvas I guess), but seems overkilling to me.

Related

setImageDrawable vs setBackground for placeholder

I am trying to find the right approach in setting the placeholder image/resource (VectorDrawable resource in my case) for an ImageView that gets set, with the target image bitmap when it is available.
There are two approaches I saw in guides. I can either set a background using the background property on XML or programmatically using setBackground(). Then, I would set the target image using setImageDrawable().
The second approach is to use setImageDrawable() for the placeholder and later use setImageDrawable() again for the target image.
Both approaches work but I have noticed some UI lag when using the first approach. I am not sure if it is caused by the approach or not.
So, I want to know. What is the correct approach in using placeholders and why?
Thank you.
The second approach is always the best for this task.
But still, if you want to go with the first approach then the correct way to use it is like this
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
setBackgroundDrawable();
} else {
setBackground();
}
when load image in ImageView changed src value, it's mean not changing background.
change background is expensive for android, It gets worse when we want to load a lot of images (like ListView, RecyclerView, ...).
for having better performance should be changed image src, not changing image background.
for changing image src you can use
image.setImageResource()
or
image.setImageDrawable()
change background suitable for a single image
In addition, all image loader support placeholder if using that's the same doesn't need set manually.

Is there an easy way to show borders around Views and ViewGroups in the design tab of Android Studio for debugging and styling purposes?

I would like to see visually how much space each box takes with as little effort/changes to the code as possible.
I would like to know if it's possible to just put a line around the outer margins of the View or ViewGroup object.
Since it's just for debugging and styling I would like to also quickly turn it off, so I do rather make the changes to my code in one place so it's easy and quick to undo. Is this a default option I am missing? Somehow I expect this feature to exist already.
Here someone asks a different but slightly related question with not a nice answer for my case.
Here someone gives an answer on how to outline one View.
Border for an Image view in Android?
Code-wise you could follow the answer to the first link you posted and create a drawable with the name "developer_borders" or something similar and apply it to every view you wish to have its borders visible.
To easily remove it afterwards, you can right-click the directory of your project and click Replace in Path.... For Text to find you want to search for android:background="#drawable/developer_borders and for Replace with don't use anything. This will find every occurrence of what you are searching and replace it with an empty string.
There might be an easier option. Some devices have quite powerful Developer Options. "Show layout bounds" is what you want but take a look at the rest while you are at it, some are pretty awesome.

How to create Options for activity

i have a couple of questions about activity's
i have a activity which i want to create some options for it. for eg. i want the user to be able to change the font size of text views.
i am a noob in java and eclipse. first i thought i can change the xml values via java but then i found out that i can't and they are read only.
so what is the best solution for creating options which are visual like changing colors and font sizes and picture through entire project?
for eg. i have 10 activities and inside each activity i have some text views. i want to change all of the font sizes. in xml you can create a dimen and all of the text views with android:fontSize:"#dimen/example will have the same size. but in java it takes more code and time.
what should i do ? couple of examples would be nice
thanks in advance
so what is the best solution for creating options which are visual
like changing colors and font sizes and picture through entire
project?
Have a look at the setTextSize() method of the TextView class. This will let you set the size of the text programatically.
setTextColor() will let you change the color.
setTypeFace() will let you change the font.
Having said that about TextView, it applies to all the subclasses of TextView like Button, EditText, etc.
i have a activity which i want to create some options for it.
I suggest you create a singleton instance that encapsulates all the information to change the visuals of your activities like text size, typeface, etc. This instance should then be shared among all of your Activitys.
couple of examples would be nice
No, an SSCCE would be nice. We need to see what you have tried. Code or you didn't do prior research.

ActionBar: Center text on navigation bar buttons

Simple aim:
To have default buttons in the navigation bar of my ActionBar with the text centre aligned. I simply want to use the default, simple way of:
ActionBar.Tab myTab = Actionbar.newTab()
myTab.setText("my tab's text");
What's the problem
I cannot find any simple way to do this whatsoever. You can't access the views (as ActionBar.Tab.getCustomView() always returns null due to it being the default view). There is no method that I can see in ActionBar, ActionBar.Tab, etc to get the current view, get or modify LayoutParams (especially Gravity). A visualisation of the problem is below (one line seems to work right, but double lined navigation buttoms definitely seem left aligned):
Unideal solution
Am I right in negatively thinking that the only way to accomplish this is to use custom views for all of my tabs, somehow guess / attempt to copy the default formatting for the tabs (as I can't find anyway to access these views) and assume / hope that the default formatting / font / style of ActionBar.Tab's text does not change any time soon?
Surely there has to be a better way?
AFAIK, there's no way you can access the Views in ActionBar. Using custom layout seems the only solution. However, doesn't Android align the text to center automatically? It apparently does so in all my applications.
please download the follwing example. it will help you. i am sure i take help from this demo.
https://github.com/JakeWharton/ActionBarSherlock

How to make an image Viewer in swing?

I am trying to make an image Viewer like the one shown in the figure below:-
Before i can start i have following questions in mind :-
How would i check for the number of images in the target folder so that i can iterate and include all the images in my app.
Secondly,i am thiking to scale the images down to 75x75 .But what i can't think is that how will i slide the images as scrollbar is moved
To be specific,what is the appropriate container for those 75x75 images queue and how that queue is shifted to left or right?(I already know how to get current scrollbar value and add event listeners on it to respond)
To check the number of images in the target folder you can use the File class.
As for the container you might need to create the animation your self. There is no a container ready for doing so.
This site ( and book ) has some ideas about it. I don't know how out-dated it might be though
http://filthyrichclients.org/
Unless I am misunderstanding, making a scrolling list of images is quite simple.
First, create a JList with a datamodel that allows images.
A great example is shown here:
Java drag and drop images in a list
Second, add the JList to a JScrollPane.
The scaling aspect can be easily performed using Scalr:
http://www.thebuzzmedia.com/software/imgscalr-java-image-scaling-library/

Categories