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.
Related
I am trying to add a bar similar to the "Today" bar here, but I cannot figure out how to force the width to match the screen. I am just using a simple textview (if there is a better way.. that's awesome, please tell it to me, but i cant find anything for it)
Here is what is happening with match_parent or fill_parent I recolored the textview to show the margins (that I dont want)
match_parent should fill the entire screen.
Check your parent activity layout or your fragment layout and you should find your margins there.
BTW, if you have a list of items like the one in the picture and you want it to have sections (like 'today', 'yesterday', etc) you should probably use recyclerview with headers instead of text view. Check this library for this, it's pretty easy:
https://github.com/cymcsg/UltimateRecyclerView
I have a ListView which I want to populate with items each of which contains only one TextView. The thing about these TextView-s is that they need to use custom font (not the one of three built-in fonts). I can not set custom font (typeface) via XML so the only way to do it is call tv.setTypeface() for all TextView-s in the getView() method of my Adapter.
Now the problem is that the font I want to use has the pretty much different line spacing (by default) so the resulting text appears larger than the same text rendered using default font (providing we use the same textSize for two fonts). This particulary affects the way ListView measures the overall size (height) of my text (and thus the size of scrollbar) thinking that text is rendered using default typeface (while in reality it is not).
When I scroll my ListView up or down the overall size of the text is constanly recalculated resulting in scrollbar changing its length (which looks weird). I wonder if there a way to tell ListView to use my custom font before the call to getView() method (i.e. during text measurement)?
It is default behaviour of ListView. Try to set smoothScrollbar to true. In XML:
android:smoothScrollbar="true"
or in code:
listView.setSmoothScrollbarEnabled(true);
It appears that the thing I am trying to achieve is impossible. Simply because there is no list item exist except for those which are visible at the moment. So the ListView does know nothing about the height of its items before they were inflated and populated with text.
What it can do - is only to make assumptions based on the item layout supplied to LIstView upon creation.
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.
I have three items in a ListView. The reason I have chosen the ListView is so I can use a Divider and a List Selector on these items.
However I do not need/want the scrolling aspect of the ListView. Ie. When I select/drag an item from the list, I dont want it to scroll..
Is it possible to disable this somehow? Or will I have to add the items using a LinearLayout and find another way of using a list divider and selector?
I'm not sure how well this will work for you, but you can disable overscroll (available in android-9 and above):
listView.setOverScrollMode(View.OVER_SCROLL_NEVER);
and then also hide the scroll bars:
listView.setVerticalScrollBarEnabled(false);
After this, if your list does not exceed the screen size then it shouldn't be able to scroll.
If you dont need to scroll listview, you can add the list item to a linear layout as well you can design it also through xml file.
And for put a DIVIDER to it just take a "View" widget.
Put it height 1 dip and width fill_parent. You can give color to this view through background color.
Try it. i have done it many times.
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?