I want to use spinner in my Activity in android application.
My requirement is, I want to show only 6 items in drop down list at one time if their are more that 6 items then scroll bar should be visible. How to achieve this requirement.
Below is the sample code I am trying for UI in android activity.xml.
<Spinner
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:spinnerMode="dropdown"
android:dropDownVerticalOffset="40dp"
android:forceHasOverlappingRendering="false" />
you can visit this link for more details
How to limit the height of Spinner drop down view in Android
You can use this awesome library MaterialSpinner that will do all the hard work for you.
Download: implementation 'com.jaredrummler:material-spinner:1.3.1'
inside your xml file.
<com.jaredrummler.materialspinner.MaterialSpinner
android:id="#+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:ms_dropdown_max_height="400dp"/>
set height using app:ms_dropdown_max_height="400dp"
Add to your xml spinner element:
android:dropDownHeight="100dp"
Related
I'm trying to put a spinner on a layout for android app. Unlike other components, the spinner does not come with an option to give a hint. How can I do it?
This is my spinner:
<Spinner
android:id="#+id/spinner_gender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/gender"
android:background="#android:color/white" />
When it's not selected I want to show a text like "Gender". When we select it i want that we can't select the option gender and that we only select Male or Female.
The options inside spinner are in an xml called where I keep the arrays.
Thanks.
Unfortunately Spinner don't have this feature built-in. Please check this post
This feature can be easily implemented through the library with so much customization:
https://github.com/Mobile-Innowise-Group/HintedSpinner
Usage of the library and with a lot of customized params:
<com.innowisegroup.hintedspinner.HintedSpinner
android:id="#+id/hintedSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
app:hintTextSize="24sp"
app:hintTextColor="#color/red"
app:hint="Custom hint"
app:withDivider="true"
app:dividerColor="#color/dark_green"
app:arrowDrawable="#drawable/example_arrow_4"
app:arrowTint="#color/colorAccent"
app:popupBackground="#color/light_blue"
app:items="#array/text" />
I have implemented AutoCompleteTextView, but in few devices (Mi and Samsung), it doesn't show options when the TextView is at the bottom of the screen.
NOTE: The Fields are dynamic, So I don't have option to move the view a bit above from bottom
image 3: check the correct here (Motorola device)
I tried:
AutocompleteTextView suggestion list goes up
Android : autocompletetextview, suggestion list displays above the textview?
AppCompatAutoCompleteTextView
Adding different windowSoftInputMode in Android Manifest
and many other things on StackOverflow, but nothing worked
my code
<AutoCompleteTextView
android:id="#+id/txt_drop_down"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:minHeight="#dimen/_40dp"
android:layout_weight="1"
android:background="#drawable/et_bottom_border"
android:completionThreshold="1"
android:gravity="center_vertical|start"
android:padding="#dimen/_10dp"
tools:text="Hello"
android:dropDownHeight="wrap_content"
tools:textColor="#android:color/black"
android:textAlignment="viewStart"
android:textColor="#android:color/white"
android:textSize="#dimen/_16sp"
tools:textSize="35sp" />
set android:dropDownHeight in xml to fixed number (e.g. 150dp). Then you will have fixed dropdown with scrollbar there. Also android:layout_height set to fixed size as well.
I want to make view, where some lines are shown as a paragraph(i.e. not as a vertical list but as a paragraph). But I also want each of the line to be clickable, so that I can prompt the user to share that specific line (to highlight or copy etc).
I am actually building an app with translation. I want user to read the paragraph both standalone(1st image) and with translation. But I want the standalone version like the 1st image below, in a paragraph format. How to achieve that using RecyclerView (as I have already achieved translation version with RecyclerView)?
On other words, I know how to use two views in a single RecyclerView, but (see the 3-5 lines of first image) how to warp one layout into other using RecyclerView
Edit: I've tried flexbox layout, it doesn't satisfy my requirement.
The answer is FlexBoxLayoutManager you can use it with RecyclerView put
implementation 'com.google.android:flexbox:1.0.0'
in your gradle file. Now setting up RecyclerView layout,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
xmlns:toools="http://schemas.android.com/tools">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/end_indicator"
android:textSize="20sp"
android:layout_marginEnd="5dp"
android:layout_marginStart="5dp"
android:textDirection="anyRtl"
android:id="#+id/line_holder"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:layout_marginStart="5dp"
android:layout_alignBaseline="#id/line_holder"
android:gravity="center_vertical|center_horizontal"
android:textAlignment="gravity"
android:layout_marginEnd="5dp"
android:background="#drawable/stackoverflow_bg"
android:id="#+id/end_indicator"/>
</RelativeLayout>
here stackoverflow_bg.xml is an oval shape drawable.
Now setting up RecyclerView,
FlexboxLayoutManager manager = new FlexboxLayoutManager(this);
manager.setJustifyContent(JustifyContent.CENTER);
manager.setFlexWrap(FlexWrap.WRAP);
manager.setFlexDirection(FlexDirection.ROW_REVERSE);
rv.setLayoutManager(manager);
rv.setAdapter(rvAdapter);
The layout I made:
As you can see this layout needs some working. The end indicator must be aligned to the last line of the TextView then it will fix the problem. Now you can even handle line click events as it is all done inside a Recyclerview.
I am currently working on an app and my layout is as follows:
I have a recyclerview holding all of my items, each item has a textview above an imageview. So the text view can expand up to 3 lines but only if needed. The recyclerview is using a gridlayout manager to display all of my items.
The problem is that currently when the text view expands to have more than 1 line it presses down the image instead of keeping it aligned with the other images in the row
What I currently have
What I want is to prevent the text view from pressing down on the image but instead build it's way up so that way the images stay normal and the text view will grow upwards like the image below.
What I want
Is there any way to achieve this? I would think it shouldn't be hard but I can't seem to find a way to accomplish this, or more likely, can't google the right terms to find the solution I'm looking for.
So I found an answer, I had to set two properties for my textview:
android:lines="3"
android:gravity="bottom"
so in the end each item had a layout below:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingStart="31dp"
android:paddingEnd="32dp">
<TextView
android:id="#+id/app_name"
android:layout_width="#dimen/product_list_image_dimensions"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/app_card_temp_name"
android:textSize="#dimen/product_list_text_size"
android:fontFamily="sans-serif-condensed"
android:lines="3"
android:textAlignment="center"
android:textColor="#color/app_name_product_list_color"
android:typeface="normal"
android:gravity="bottom" />
<ImageView
android:id="#+id/app_thumbnail"
android:layout_width="#dimen/product_list_image_dimensions"
android:layout_height="#dimen/product_list_image_dimensions"
android:layout_below="#id/app_name"
android:paddingTop="#dimen/product_list_text_bottom_padding"
android:scaleType="centerCrop"
android:layout_centerHorizontal="true" />
</RelativeLayout>
i am using spinner in my code which i had declare in my xml
xml code for spinner:-
<Spinner
android:id="#+id/spinner"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/button1"
android:layout_marginTop="133dp"
android:drawSelectorOnTop="true" />
so as can be seen that the spinner is down the one button which is also in that layout xml .Now when i run my app its loading all data correctly but the item is showing in the top of the spinner not in the down side of the spinner.Mentioning the screenshot how it appear
but when i m using the same spinner parallel to the button the spinner dropdown effect working very fine.Here is the screenshot how it appear.
so can any tell me how can we solve this kind of scenario.thanks for any reply.
try this hope this will help you
android:spinnerMode="dropdown"