How to set the size of spinner - android

I want to know how to set the size of spinner.When i added large values to spinner list,the spinner expands and as result it pushes the labelField to the further left.
I want to know the how to set the spinner size to be a constant one

Presumably, you presently have the Spinner set with android:layout_width="wrap_content". That will expand as the values expand. If that is not what you want, do something else. RelativeLayout is particularly useful here, as you can anchor both the left and right sides of the Spinners to things they should not expand past (e.g., left to another widget, right to the right edge of the screen).

Just in case anyone come to this page again... One may refer to here:
How to change spinner text size and text color?

Related

Why is not working my horizontal scrolling done programmatically?

I'm trying to make horizontal scroll in TextView bRes programmatically. Reading some answers and tutorials, I've included some settings.
bRes.setHorizontallyScrolling(true)
bRes.setMaxLines(1)
bRes.setMovementMethod(ScrollingMovementMethod())
bRes.setScroller(Scroller(this))
I put in the left and right side of TextView, small left and arrows black triangles with a click event to make right and left scroll if text width surpasses the view width. The buttons just appears if they has some action to do.
When I set the text in TextView, I call this code
fun changeRes(t:String){
bRes.text = t
bRes.post{ bRes.scrollTo(0,0) }
val largu = bRes.getPaint().measureText(t)
bRight.visibility = if (largu > 0.99 * bRes.width)
View.VISIBLE else View.INVISIBLE
bLeft.visibility = View.INVISIBLE
}
I've selected put the text excess in the right side, i,e, when the text is wider than TextView, the left black arrow is invisible and the right black triangle is visible.
Well, with this the text disappears completely. If I comment the line
bRes.post{ bRes.scrollTo(0,0) }
the text appears again, but there is no scroll. I don't get to see the left excess characters. The bRes.scrollX value should by 200/300 pixes but is over 1 million!
The first parameter, according documentation, is the number of pixels invisible to left of the TextView.
PS: I've used exactly the same procedure to program a vertical scroll in another TextView and it works very well. I don't use ScrollView, I've directly programmed a scrolling in my another TextView.
PS 2: I've created all my layout dinamically. No XML for layouts.
Somebody has some help for me?
I have no idea about it, except put the text in TextView manually in each change.
What kind of layout are you using? It should not be a LinearLayout, but rather a FrameLayout or RelativeLayout
I've made a workaround that is working very well for me. It's sad that I haven't found a more direct way to do this:
a) I've put 2 triangle arrows inside 2 small buttons to the left and rigth of TextView.
b) The buttons are visible or not depending if has or not scroll hidden text in its respective direction.
c) I've used the event OnTouchListener to accept click in the scroll buttons or 20% of TextView width nearest to each arrow for getting more hidden text in that direction (I've made this because the arrows are small and prone to touching in a wrong place.
d) I have to keep inside a tag (extra field of the widget) a complete text value of the widget.
e) For calculating which text I have to put in a field, I've programmed a heuristic using
widget.getPaint().measureText(string)
The visual is something like this:
PS: The ideal isn't using horizontal scroll, but if it is necessary, I think that the above appearance is nice and it is practical for users. I don't like the marquee solution where text moves alone: thinking as user, it's annoying.

Custom width for an ActionBar Navigation Dropdown (Android)

I have a custom drop-down navigation ActionBar spinner and it works pretty well.
Only problem is, the width of the dropdown menu is always the same as that of the spinner.
Since the text in the spinner changes according to content, it sometimes gets ridiculously thin, which as demonstrated below, can be a problem...
I know that it's possible to set a dropdown width for spinners, but this isn't a regular spinner, it's not actually in the xml because it's a sub-view of the ActionBar.
Is there a way to interact with that view directly to set a width to the dropdown?
Is there another way to make the dropdown conform to the actual text in it?
Thanks in advance.
Oddly enough, this was solved the moment I changed the dropdown resource conatiner from a RelativeLayout to a LinearLayout. Specifically, it's the fact that the text was aligned to the left of the imagebutton that broke the design.
The moment I disabled that alignment or changed the entire thing to a linear layout, it started adjusting to the content's width.

ExpandableListView with custom row backgrounds

I'm an Android newbie. I want to create a screen with some expandable headers as illustrated. I've created the 1st row "gff" as shown.
However, each row under gff shows a space in between rows. Also, the ListView does'nt fill the width of the screen and leaves a margin on the sides and above.
How can I get the header and caption to fill the entire length of the screen as shown in the diagram? Also, how can I get the rows to show a different color?
Is there an example or code that does something similar?
Try setting divider of ListView to null, like listView.setDivider(null), this should help. Also you can set listView.setSelector(null) this should remove unnecessary margins.

How to make this Android bubble ListView list item so the background adjusts with the text size

How would I make a ListView like this ?
I know how to make a customized ListView, but I do not know how to adjust the size of the background with the entered text so the text fits in the background.
Can anyone help me with tutorials or put me in the right direction?
Here is a nice example with source code,
Bubble ListView like Iphone
You can use a relative layout to align your text to the right or the left, and a wrap_content value for the width or your textview

Only show the arrowbutton of a spinner

I would like to use a spinner but only show the arrow on the right side like Android does in it's settings menu. (like for example by Screen timeout)
I can set the width to +/- 65px but then I've only got rounded corners on the rightside and not the left.
Thnx for your help!
Patrick
Are you sure they use a spinner?
You could achieve the same thing by simply placing a round button to the right-hand side and when pressed it triggers a popup ListView. The drawable for that button is...
"#drawable/ic_btn_round_more_normal"
If you are just trying to get it the dropdown to be all the way to the right rather than narrower, you can simply set the tag on the spinner in the xml to use android:layout_width="fill_parent". If you want to just have the button without the border, the Android Preferences have their own layout objects. I have just asked at elsewhere how to get those elements in a non-preferances view: Howto make a layout similar to the ones in settings.
What I did is the following:
Set the layout_width of the Spinner to 48dp and in code set an adapter which serves views with a size of 0dp x 0dp. The dropdown view is a normal (visible) view.

Categories

Resources