Too much blank space in the spinner - java

I'm a beginner devoloper. I'have a problem with Spinner in my xml file.
The spinner is this:
<Spinner
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/spinnerA"
android:gravity="center"
android:text="Symbol A"
android:entries="#array/teamList"/>
There is too much black space between the end of text and the down arrow of spinner. As you can see, the word "Atalanta" is truncated in Atala.., but there is a lot of blank space on the right. How can I solve?
Thank you for helping me

Replace -
android:layout_width="match_parent"
android:layout_height="match_parent"
with -
android:layout_width="wrap_content"
android:layout_height="wrap_content"
and when you see the output in any device , you will see the proper output.

There is a listPreferredItemPaddingEnd in the default layout simple_list_item_1.
So you can use your own spinner adapter with your own layout item.
You need to create an arrayAdapter, override the getView method and return your own item view.

I solved, adding android.paddingRight=0dp to the Spinner. In this way, there is more free space and the word "Atalanta" is not truncated in Atala..

Related

Set visalbe border to matrix in XML

I have a matrix-like structure. Each row is a LinearLayout of n-TextViews. Both are created programmatically and added to a LinearLayout "container". In XML:
<LinearLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
This is how it looks in App after building a matrix at runtime:
I always want to add a border to first/last column as well as to the first and second row, for each mxn-matrix. I want it to look like this:
I think the border / frame has to be added programmatically as well.
So my approach would be something like building a TableLayout as container and replace the LinearLayouts for each row with TableRows.
After that set the background color of TableLayout to black and give every needed TextView a padding on the right place programmatically.
But this seems to be a very stressful task. So I really hope there is a better way to do that.
I am using Kotlin.
I am very thankful for every suggestion!

How to break lines at a given character if the text is forced to wrap in your textview? (android)

So I have my textview's height set to wrap content. It displays a sports score in the format
"CHI 99 CHA 88". I have the textview match the parent for its width. I also have the score text set to a specific textsize in "sp" units.
So on smaller phones, if there are more characters in the score, or if font size (accessibility settings) is changed, there is a chance that the text will need to wrap into 2 lines. However, I would like a way to control where (in the string) it will decide to wrap the text and make a new line. It would look best in the form
"CHI 99\nCHA 88". But I prefer the text to be on the same line unless it is forced to wrap by screen size, character count, or accessibility settings, so I don't want to hardcode in a "\n" from the beginning.
So basically, is there a way to control what character the text decides to create a new line at if there is a necessity for the text to wrap onto a new line.
Thanks for any responses!
Instead of programatically calculating display sizes/characters, etc., Flow widget with two TextViews can be used control this.
An example layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="150dp"
android:layout_height="match_parent">
<androidx.constraintlayout.helper.widget.Flow
android:layout_width="0dp"
android:layout_height="wrap_content"
app:constraint_referenced_ids="text1,text2"
app:flow_horizontalBias="0"
app:flow_horizontalGap="5dp"
app:flow_horizontalStyle="packed"
app:flow_wrapMode="chain"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CHI 99" />
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CHA 88" />
</androidx.constraintlayout.widget.ConstraintLayout>
Normally, with default sizing, it looks like this:
If the views cannot fit horizontally, second TextView moves to the next line:
you can avoid line breaks by use autosize and set maxLines to 1 like this:
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:autoSizeTextType="uniform"
android:autoSizeMinTextSize="12sp"
android:autoSizeMaxTextSize="100sp"
android:autoSizeStepGranularity="2sp"
android:maxLines="1" />
Source: https://developer.android.com/guide/topics/ui/look-and-feel/autosizing-textview
You can calculate characters in one line according to screen width and add new line character after that.

EditText auto suggestions are blank or non existing

I have a standard straight forward EditText, I want to show the dictionary suggestions on top of this EditText so I did this in the XML:
<EditText
android:id="#+id/messaging_messageEdit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:layout_weight="85"
android:background="#drawable/clanz_edit_text_holo_dark"
android:ems="10"
android:hint="Type your message here..."
android:singleLine="true"
android:inputType="textAutoComplete"
android:textColor="#dedede" >
</EditText>
I thought that the inputType parameter would take care of the auto dictionary view. On my phone (Nexus Android 5.1) the dictionary view appears but is blank. On a Genymotion emulator (Android 4.1.1) it does not display at all.
What am I missing?
This can be one solutions if you are looking for AutoComplete TextView.
<AutoCompleteTextView
android:id="#+id/from_station"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="#string/enter_start"
android:imeOptions="actionNext"
android:inputType="textNoSuggestions"
android:textColorHint="#color/transparent_black" />
You can also set threshold value using paramters.
Need to set adapter values at runtime.
If I understand correctly you want the keyboard to have auto correction right?
According to the Android developers website:
Can be combined with text and its variations to specify that this
field will be doing its own auto-completion and talking with the input
method appropriately. Corresponds to TYPE_TEXT_FLAG_AUTO_COMPLETE.
This is not what you're looking for. You are probably looking for textAutoCorrect which is this according to the Android developers website:
Can be combined with text and its variations to request
auto-correction of text being input. Corresponds to
TYPE_TEXT_FLAG_AUTO_CORRECT.
I've made a lot of apps and never used one of those though. It just auto corrects if you have a normal EditText.
I had the same problem not getting keyboard suggestions on some of my EditText views. Please pay attention there is a difference between autoComplete text views and getting keyboard suggestions while typing! They happen in two different places, first one inside the AutoCompleteTextView the other one on top of your keyboard while typing.. (for example you type te => it suggests "tea teaspoon teapot" to make your life easier.)
To achieve that I had to turn off the input types that I was setting programmatically and when you do so, the default behavior is back and that means getting keyboard word suggestions:
// etFieldValue.setInputType(InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
I tried the following but I still did not get a keyboard suggestions:
etFieldValue.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE|InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
at the end I commented all the above and it worked just fine!
here I also found that someone else had the reverse problem meaning they wanted to disable this functionality and they suggested to use the code that I had commented! read here

Horizontal EditText scroll one character at a time

I'm using the following XML attributes for my EditText:
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:hint="#string/edit_message"
android:lines="1"
android:maxLines="1"
android:scrollHorizontally="true"
android:typeface="serif"
Currently, when the text of my EditText becomes longer than it's size, the cursor moves to the beginning, and all of the previous text is backed up out of sight.
When the text of my EditText becomes longer than it's size, a new line begins, and the height of the EditText stays the same.
I want my EditText to scroll similar to the Google search bar; once the text becomes too long, the cursor should remain at the end, and as further characters are typed, the previous text should move backwards only one character at a time.
Here's a video displaying my problem.
Have you looked at the Ellipsize attribute, this solved a similar issue for us. TextViews also have the attribute android:singleLine="true" which is most likely to be what you are missing

Android - Creating a dynamic TextView

I am creating an Android game and have an issue with dynamic text with a TextView. Essentiall within my layout, I have a TextView, within a Relative Layout with enough space for several lines.
What I would like to do is add 5 lines within the TextView, with a functionality that once it is trying to write a 6th line it automatically overwrites line 1, therefore only ever showing a max of 5 lines of text.
Example of What I am after:
dynamic line 1
...
dynamic line 5
Please find below my xml code:
<RelativeLayout android:id="#+id/battleconsole"
android:layout_width="fill_parent"
android:layout_height="135dp"
android:gravity="center_horizontal"
android:layout_below="#+id/spacer1" >
<TextView
android:id="#+id/battle_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Console with information" />
</RelativeLayout>
This is the code that I am using to update the text within the TextView:
TextView update = (TextView)findViewById(R.id.battle_details);
update.setText("test console data going in here");
I am not sure if this is even possible using a TextView, if not is there any other way I can solve this issue?
Thanks in advance
Keep the 5 lines in a collection (array or list). When you set the text on the TextView, join the lines in the collection on "\n". Then just replace the item in the collection with the updated text.
Android has a join method in the TextUtils class, but I prefer the Guava library's Joiner class. Check it out: Google Guava

Categories

Resources