How to add textview small texts - java

i want to make a program. I have 16 textviews that includes letters. And i want to add small text to every textview -programmatically-. Please refer to the pictures..
firstly --> picture
after adding --> picture

You may do this:
Instead of getting textviews into the program, you can create a layout file which contains 2 text views. You may need to use "layers" to do this. One for big text, other one for the little text which contains the reduced size texts. Then inflate the layout file to a view by an inflater. Then use that view instead of textview. So you have little numbers on you table now.
I don't know about RecyclerView, may be that can be a better solution but as i said i dont know it so here is my answer, good luck at your project!

Related

TextView is being cut off in CardView?

Good Afternoon, I want to build a Card View with information but everytime I try to build it, the last part of the text gets cut of even though there should be space.
XML file:
I have attached an image on what the issue looks like and don't worry all the information in the photo is fake, is there something I am missing from my layouts that is cutting the text a bit earlier than it should be.
Edit:I have fixed it.
It depends on the height of the cardview or "dropdown_printer_setting" linearLayout. Try putting wrap_content.
Add a constraint layout inside of the card view then add in the other views as child elements.
Also why do you have a fixed height for the card view ? try increasing it to fit or wrap_content. the 120sp you could also try changing it to dp as sp is usually used for text size
You should try and increase the height of the card view from 120 to at least 150dp and not sp, this should fix your problem

Android Staggered/Multi-line Linear Layout?

For my app, I'm trying to have a section listing the tags in an article but I wasn't able to find an Android Layout that can achieve this.
Basically, I have an array of strings which contains anywhere from 1 to 5 elements. I want to be able to list them in an manner in which they're sort of staggered. Similar to what a Horizontal LinearLayout would do except it goes to the next line if the next view is too large. I'd have to do this programatically and without a ListView/GridView since it's inside a ScrollView.
Is there any way to achieve this?
Here is an edited image of what I mean...
http://i.stack.imgur.com/Hhpry.png

How to handle a large textView that get's cutoff on small screen sizes in Android?

I have a textView that fits perfectly on my Galaxy Nexus and it takes up the whole screen. I'm trying the application out on lower resolution devices and my text is getting cutoff. What's the easiest way to alleviate this?
Stick it inside of a ScrollView.
EDIT: If you can't use a ScrollView, something like this might help. Basically, you would extend TextView and it would recalculate the text size whenever the size of the view changes.
If you can't put in a ScrollView or make in 2 lines, another option is to have a different smaller text for lower resolutions.
You can do this on java by writing with \n it will gets new line.it automatically looks like scroll view.

Android layout in java code

i'm making an app that requires indefinite textviews and images. i'm trying to implement a Pulse News app UI but having a hard time implementing one. so i thought of an idea to make a UI like that with the use of textviews, imageview and horizontal scroll view.
textview string values are from parsed xml online and images or the imageviews will be images from a specific directory in the sdcard that my app is using.
can anyone give me ideas how can i do it without using an xml layout or is there any or other options or ways for doing this? thanks...
You can create a viewgroup with one textview and an image. Then it can be added dynamically to your layout many times. This can be done by creating objects in a loop. You can change the content in each viewgroup at the time of inflation.
though i dont know what exactly how pulse new app looks like, but by going through your question (horizontal scroll view in particular) I guess you want to implement a "Gallery" type implementation where in you can swipe left/right on page basis.
If my assumption is correct then you will like to see to ViewPager of android backward compatiblity pkg.

Dynamically Displaying Text with TextView (Android)

Basically what I want to do in my Android app is use TextView to display two different pieces of text at once. So in code, I want to be able to do something like this:
LinearLayout ll = new LinearLayout(this);
TextView text = new TextView(this);
text.setTextColor(0xFF000000);
text.setGravity(Gravity.CENTER_HORIZONTAL);
text.setTextSize(20f);
text.setText("Text1");
text.setTextSize(14f);
text.setColor(0xFF0000FF);
text.setText("\nText2");
ll.addView(text);
To clarify, I am trying to display a black "Text1" and a blue "Text2" at once using only a single TextView. Obviously this doesn't work out using the code above. I've considered using a second TextView but that seems like a waste of effort and memory to me. I'm sure the brilliant minds here can come up with the best solution to this.
Thank you very much in advance for your time and your assistance.
There are two options for you.
One is
Spannable
and other is
fromHtml (String source)
So that you can get your desired output.
I think with the current version of the code, you can see only the latest text (Text2).
If you want to have multiple look and feel for two texts, I would suggest use 2 separate TextViews. It would add more flexibility.
If you are not going to change this UI code later, then you can consider Html.toHtml() in setText() call.
It seems the problem is with:
LinearLayout.addView(text);
You are trying to add a view to a LinearLayout, but the layout doesn't exist (in the current activity). You need to add the TextView to a Layout defined in the .xml you are using. Suppose you have a LinearLayout with id "linearlayout01" in the xml file "activity1.xml", you would do something like:
setContentView(R.layout.activity1);
// Create and adjust TextView text
...
LinearLayout layout = (LinearLayout) findViewById(R.id.linearlayout01);
layout.addView(text);
Once a View is added to a ViewGroup of which LinearLayout is a descendant you do not need to readd it to update its display. If you preform any changes on a view that requires it to change its display it will handle all the proper notifications about required redraws or relayouts by calling View#invalidate and View#requestLayout where appropriate.
In addition, because all UI changes are handled on the same thread you do not need to worry about calling multiple methods that will update the UI. This is because of two reasons, first, the execution of the redraws will not occur until your code is finished, second, android has optimizations built in that combines multiple invalidate calls into one.
So, the only thing you need to worry about is getting a proper reference to your TextView instance and then you can call all the methods on it that you need to make it display what you wish.
Since you are creating your Views manually and not from xml you need to add your root ViewGroup to the Activity by calling Activity#setContentView.
Edit:
Then you're going to need to learn about SpannableString and SpannableStringBuilder. There is some very brief documentation here: Selecting, Highlighting, or Styling Portions of Text
when do you plan to update the textview ? If it is on click of a button then get a reference to the textview and in the onClickListener() update the text, color, etc whatever you want to do.
After seeing your other comments, I think SpannableString is what you are looking for

Categories