I have an Autocompletetextview dropping down the suggestions list, up to the border of the soft-keyboard.
Then, when scrolling over the suggestions list:
- (in a gingerbread phone) the drop-down-menu automatically increases height covering the keyboard, which is nice since it shows more items.
- (in an ICS emulator) the drop-down-menu does not increase height over the keyboard.
Is this related to some system property?
Is there a way to force the first behavior also in ICS?
Just add android:dropDownHeight="100dp" to the AutoCompleteTextView tag in your layout file, it will work.
Let me explain my little trick to avoid that the "drop-down" displays behind the keyboard. The trick is with the dropDownAnchor property.
The solution is set the anchor with a view located on the top of the screen, so the menu will leave from that position, and therefore, will not be covered by the keyboard. For example:
android:dropDownAnchor="#+id/topview"
I know that is an ugly solution but this control is too limited.
You can also use android:dropDownAnchor="#id/ to anchor the dropdown to a view.
Just add getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); to your fragment or activity
A simple solution that works perfectly with all resolutions is to use the android:dropDownAnchor property with a resource ID that references your activity toolbar.
<my.app.ContactAutoCompleteTextView
android:id="#+id/autocomplete_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:dropDownAnchor="#id/appbar"
android:inputType="text|textMultiLine|textCapSentences|textAutoCorrect"
android:paddingBottom="12dp"
android:textColor="#color/text_primary"
android:textColorLink="#color/secondary"
android:textSize="#dimen/text_medium" />
You need to do two things.
First, adjust the soft input mode of that activity in the manifest.
android:windowSoftInputMode="stateHidden|adjustResize"
This ensures views are laid out again when the keyboard is shown. Then, set a global layout listener in your oncreate on the top level view to do the dropdown height calculation when the layout changes. Adjust the dropdown height to be the height of everything below the keyboard, minus some padding if you want.
v.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
autoCompleteView.setDropDownHeight(view2.getHeight());
}
Where view2 is the view/layout that includes everything below the autocompleteview.
If none of the above solutions worked. try this
android:dropDownHeight="match_parent"
or
android:dropDownHeight="500dp"
If we didn't mention the dropdown height, it would be considered wrap_content. Therefore the item will show behind the soft keyboard.
Related
I started using ConstraintLayout a few weeks ago and I am finding (I believe) that it has many bugs. One huge issue is that I cannot set view visibilities. The following code does not work:
<TextView
android:visibility="gone"
android:id="#+id/sampleView"
style="#style/RSTextView"
android:layout_width="0dp"
android:text="sample text"
android:textSize="20dp"
android:shadowColor="#00000000"
app:layout_constraintStart_toEndOf="#+id/privacyPolicyText"
app:layout_constraintTop_toBottomOf="#+id/enterAgreementText1" />
You can see I've marked it as "gone", but when I run and inspect the view using the layout inspector, visibility is STILL set to visible. I've had to come up with hacky solutions to this involving setting the alpha to 0 and isEnabled to false when I want a view to be gone and vice versa. When I try to set the visibility programmatically, I have the same issue:
sampleView.visibility = ConstraintLayout.GONE
This still results in a visible view. This is driving me nuts because I'm forced to make multi-line hacky solutions. Any help would be appreciated.
Be careful using Groups in Constraint Layout. Main things to note while using groups are
Group's visibility overrides normal view's visibility
If the group's visibility is unset, it defaults to visible and overrides your view's visibility.
While using Constraint Layout be careful in using Groups. I think almost all visibility issues in constraint layout are caused by groups.
I don't know if the below links I found are related to your problem:
https://issuetracker.google.com/issues/37151322
https://issuetracker.google.com/issues/37139335
https://issuetracker.google.com/issues/37138937
but they are all filed reports about problems/bugs concerning the visibility of views inside a ConstraintLayout.
Check them.
#Pavan Varma pointed out that Group visibility overrides the view's visibility. I thought that if the groups visibility was unset, it wouldn't override anything, but it still does. If you're having issues with visibility in ContraintLayouts, pay close attention to its group's visibility that overrides it. If the group's visibility is unset, it defaults to visible and overrides your view's visibility.
I have a RecyclerView list where some items (text) are too long for the width allowed by the device. I can use android:ellipsize="end" to indicate that the text is truncated but I want to be able to show user the whole text. I can use android:scrollHorizontally="true" and then the text will scroll but there is no visual indication for the user that he needs to scroll it and the text just looks truncated. What would be the good UX for this case? Thanks.
1、you can edit your textView like this
xml
<TextView
...
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:text="......"/>
It will auto scrollHorizontal,Or you can use a autoFitTextView in you list item,auto fit textview.
You can add android:scrollbars="horizontal" to your recyclerview to show the scrollbar.
Turned out that the solution is to wrap the item in HorizontalScrollView and set android:layout_gravity="fill_horizontal". This allows for scrolling and there is a horizontal scroll bar for long items.
So, after many investigations, I've found the problem solution:
This happens due to MARGINS and PADDINGS (and maybe other offset parameters) inside your TextView and its parents. Just remove them and see the result.
I hope it helped new googlers!
PS:
If you want to save your offset parameters try to change the layout width parameter inside your TextView and its parents to wrap content (but somewhere also try 0dp or match parent), it also worked for me. So your UI will look exactly as you want!
I am working on an android app and I have a scrollview, and in that, I have a linear layout in the main activity. I want to have the top and bottom borders of the linear layout to be "faded
" so as the user scrolls down the child views in the layout will "fade out" as the go down.
Here is an example of what I am trying to achieve in my linearlayout or scrollview (the "fading bottom border".
Thanks for you help!
Subby
You can do that by using the following attributes in the ScrollView.
android:requiresFadingEdge="vertical"
android:fadingEdgeLength="20dp"
If you want it on devices before API14, you need to use the following:
android:requiresFadingEdge="vertical"
android:fadingEdgeLength="20dp"
NOTE: This is actually discouraged as it is seen to have a negative performance impact on devices.
At the bottom of your layout, you can have a view above the listView, and set Gradient Color for the view, and also make it semitransparent, then you can have the effect you want.
If i try to make the thing u see in the screenshot it just falls back to original size. I can't change sizes of any view Objects. Anybody knows a fix?
http://imgur.com/2S1xoLP
In Eclipse (as you're using the designer), you can set the Width and Height of a View, within the Layout Parameters section of the Properties pane. This can be set to wrap_content, match_parent or fill_parent.
You can also do this within the XML markup of the activity you're editing. Click the .xml tab at the bottom of your designer, and you'll see all of the XML that makes up your activity. Once in there, find the problematic view and add:
android:layout_width="match_parent"
android:layout_height="match_parent"
Edit
Also, when inside of a RelativeLayout, it's possible that Eclipse will add default padding values, so regardless of what you set, your View's wont reach the parent layout's edge, until you remove them. Just FYI!
I've created an android application with a ListView. I've added both a header and footer to the list. But when adding a divider/separator it also creates an empty space between the header and the first ListView item. It does the same for the last ListView item and the footer.
The empty space is equivalent to the size of the divider between all the ListView items, with the difference that it doesn't draw the divider and just leaves empty space. I thought I found the solution with the xml attributes 'Footer dividers enabled' and 'Header dividers enabled'. But when setting them to false, it doesn't change anything. I even tried to set them programmatically with
list.setFooterDividerEnabled(false);
list.setHeaderDividerEnabled(false);
But it just doesn't work. Any way to fix that problem? I just don't want the empty space to be there, I want the first item to fit exactly to the header (same for the footer).
I stumbled upon the same problem, but in a slightly different situation than yours. My ListView has a header (a search box), but the first item below it contains a section header (a date, or a letter) rather than being a regular list item (with the actual content in form of an image, some text, and so on). As such, I want it not to be selectable, so in my custom adapter I have overridden areAllItemsEnabled to return false.
Big mistake, because that's exactly the culprit. See, it appears that, by design, the ListView implementation only draw dividers between two enabled items, but still reserve space for dividers between an enabled item and a disabled one even if those dividers will not be drawn. The fact this is a conscious design decision does not mean it's not stupid, of course. Most weird of all, this dividers drawing policy is based just on the value returned by areAllItemsEnabled instead of the values returned by single calls to isEnabled for subsequent items.
Thus, to work around it, I just had to return true from areAllItemsEnabled (I kept the overridden method and add a comment about this issue, otherwise I would not be able to remember it a month from now): lo and behold, white space disappeared, replaced by a divider. Now, if I want to show the ListView header and the first section header as being exactly adjacent, I just have to choose a divider color that's the same as the section header color.
Really hope that's the same case as yours, or that my solution helps you in some other way.
I tried a solution by 幻影浪子 that works (based on android-pulltorefresh):
View Layout (header.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ProgressBar
style="#android:style/Widget.ProgressBar.Small.Inverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="16dp"
android:layout_marginTop="2dp" />
</RelativeLayout>
</LinearLayout>
Inflating View:
m_headerView = inflater.inflate(R.layout.header, this, false);
Displaying View:
m_headerView.setPadding(0, 0, 0, 0);
m_headerView.setVisibility(View.VISIBLE);
Hiding View:
m_headerView.setPadding(0, -1000, 0, 0);
m_headerView.setVisibility(View.GONE);
It worked perfectly in our project. I hope it is helpful.
In getview method you can check if the item is first or last and set custom devider which will be of 0 height or single pixel height of transparent color.
goto the ListView properties in android layout and search for spacing tag... some how in android, when creating new layouts, it will defaults creation is spacing header spacing and border properties. check it , if it is available then remove it
Didn't find a great solution.
Set dividerHeight="0dp" and created my own dividers manually - either directly in the layout XML or dynamically in the adapter if you need more precise control.
Just do
list.setDividerHeight(0)
That should take care of it.