Adding padding on android AutoCompleteTextView popup - android

For the last two hour and a half i had been trying to do something really simple: change the padding in the Android's AutoCompleteTextView's popup (the one that shows the auto complete options).
i'm trying to do this because the item in my app has the height of the text (i'm not sure why), so i want to make it easier to click on. But every think i could find didn't work at all.
So i really would be glad if anyone could spot a light in this problem or give an alternative solution.
And just for the record, i'm using android studio, and i had removed the support API (since my min API is 16), so my app is using 100% native resorts only.

I just found a way to make it, i had to make a custom view layout with an textview already including the item's padding. Than i created a custom adapter with uses this layout.
The layout goes like this
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:layout_margin="0dp"
android:paddingLeft="#dimen/thin_margin"
android:paddingRight="#dimen/thin_margin"
android:paddingTop="#dimen/list_1line_item_padding"
android:paddingBottom="#dimen/list_1line_item_padding"/>
And in the custom adapter just used it in the getView method
itemView = LayoutInflater.from(ctx).inflate(R.layout.list_1line_item, null);

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="20dp"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="#dimen/dp_15"
android:paddingBottom="#dimen/dp_15"
android:id="#+id/parentid">
<AutoCompleteTextView
android:id="#+id/address_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/light_gray_bg"
android:drawableRight="#drawable/icon_search_smaller"
android:gravity="center_vertical"
android:hint="Start typing location"
android:inputType="textCapWords"
android:popupBackground="#drawable/auto_location_popup_bg"
android:textColor="#color/black"
android:textColorHint="#color/dark_grey"
android:textSize="16sp"
android:visibility="visible"
android:dropDownWidth="wrap_content"
android:dropDownAnchor="#+id/parentid">/>
<requestFocus />
</RelativeLayout>
</RelativeLayout>

define another relative layout wrapping only the autocomplete textview and the button. look at this link
Android layout padding is ignored by dropdown

Related

When aplying exposed dropdown menu style for a dropdown menu on android studio my activity_main.xml disappears

I am trying to implement a dropdown menu on my app but anytime i try to choose any material option for style it makes the whole activity_main.xml disappear.
I have done it before in other projects that i use to test things before implementing in the final app and they work, i looked for any differences between projects but i dont find any.
this is the code snippet in the activity_main.xml
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:layout_weight="1">
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:inputType="none"
android:text="Chose level and press play"
android:gravity="center"
android:fontFamily="#font/gomarice_coffee_jelly_umai"
android:textSize="30sp"/>
</com.google.android.material.textfield.TextInputLayout>
Here is the tutorial I followed: https://www.geeksforgeeks.org/exposed-drop-down-menu-in-android/
photo so you can have an idea
I have tried every materialDesign with the name dropdownmenu.
What I expect is to display a dropdown menu.
Im also having problem with other .xml file needed for the dropdownmenu
This file has a disappeared background, so maybe it has something related
This is the first time i ask, hope the problem is clear enough, and sorry for the language mistakes, i'm from Spain.
I think your issue is in AutoCompleteView.
The android:layout_height should be wrap_content and not match_parent.
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
...
/>

Android RelativeLayout zIndex not working (anymore)

I don't understand this issue. I'm pretty sure I used to do this, yet in this case, the zindex ordering is not followed, and the TextView below is hidden behind the button:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="Button"
android:layout_width="match_parent"
android:layout_height="50dp" />
<TextView
android:textColor="#color/black"
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
I have restarted Android Studio, but even worse, this is the same on my device too, so its not an Android Studio bug. What is the issue here exactly?
Please use the elevation
android:elevation="10dp"
here is you can see your solution
If you add any views to Relative Layout, It places your view above another view if you don't use layout alignment like layout_above/layout_below/layout_leftof or rightof etc

How to get rid of a TextView's margin?

This layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="90sp"
android:text="5000"
android:id="#+id/textView"
android:layout_gravity="center"
/>
</LinearLayout>
produces the following:
I want to get rid of the top and bottom margin. Where are they coming from in the first place? Maybe for certain letters in certain fonts/languages.
There is already a thread for this question, but none of the answers really work in all situations or the solutions are hacks. There has to be a simple way.
First idea from the thread: android:includeFontPadding="true" (does not change anyting)
Second idea from the thread: android:height="90sp" (removes at least bottom margin)
So, I changed my layout regarding the ideas:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="90sp"
android:text="5000"
android:id="#+id/textView"
android:layout_gravity="center"
android:includeFontPadding="true" <!-- idea 1 -->
android:height="90sp" <!-- idea 2 -->
/>
</LinearLayout>
Still it procudes a top margin:
Third idea from the thread: android:layout_marginTop="-12sp"
If add this property it looks at least as desired. But -12sp seems so arbitrary to me. I just adjusted this value via trial and error and I don't like that.
This does not seem like a clean solution to me. This is such a simple thing, I just cannot believe how Android can make it so hard, that you have to use hacks.
Is there a clean solution out there?
Use the below syntax to set text size programmatically and set the required size in dimes file.
textView.setTextSize(getResources().getDimension(R.dimen.textsize));
To set padding use below code based on your needs
yourTextView.setPadding(0, 10, 0, 0);
Set Linearlayout and TextView padding and margins to 0dp. Should work.
Add those to both views:
android:padding="0dp"
android:layout_margin="0dp"

How can I create a multiline, multicolumn list item layout?

I am creating a messaging app and am currently working on the inbox. I'm using a RecyclerView to display the list of conversations and would like each list item to look like this:
Leftmost is the contact image at 90dp x 90dp
The first row has two columns--the contact name and the date. The date should not be a fixed size as I currently have it, but fit at most DD/MM/YYYY (can be smaller in the case of something like "Sunday") and should be anchored to the right margin. The contact(s) should expand as necessary to fill any space up to the date.
The second row contains as much text of the last message as will fit.
I was going to use layout_weight but that doesn't work in a RelativeLayout (and doesn't allow the contact names to elongate in the case of a shorter date) and LinearLayout doesn't let me use layout_toEndOf. I'm a newbie at Android development so I'm not sure if one of those is the "right" answer.
What's the proper way of accomplishing the layout I'm looking for?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/conversation_info"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/activity_horizontal_margin">
<RelativeLayout
android:id="#+id/conversation_image_layout"
android:layout_width="90dp"
android:layout_height="90dp">
<ImageView
android:id="#+id/conversation_contact_image"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
<TextView
android:id="#+id/conversation_contact_name"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:gravity="center_vertical"
android:textSize="#dimen/conversations_contact_font_size"
android:layout_toEndOf="#id/conversation_image_layout" />
<TextView
android:id="#+id/conversation_date"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/conversation_contact_name"
android:gravity="right"
android:paddingRight="#dimen/activity_horizontal_margin"
android:textSize="#dimen/conversations_date_font_size" />
<TextView
android:id="#+id/conversation_snippet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/conversation_contact_name"
android:textSize="#dimen/conversations_snippet_font_size"
android:layout_toRightOf="#id/conversation_image_layout" />
</RelativeLayout>
</LinearLayout>
This is what a list item currently looks like (I haven't loaded contact images yet). It's fine for the most part (though my layout code is probably incredibly bloated so I'd appreciate if anyone could point out ways to make it more concise) but notice how the date isn't on the same level as the contact name and wraps:
One of the textView in question has the MarginTop attribute, and the other one doesn't. Either remove it on both or add it to both:
<TextView
android:id="#+id/conversation_contact_name"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:gravity="center_vertical"
android:textSize="#dimen/conversations_contact_font_size"
android:layout_toEndOf="#id/conversation_image_layout" />
<TextView
android:id="#+id/conversation_date"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/conversation_contact_name"
android:gravity="right"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:textSize="#dimen/conversations_date_font_size" />
Also, I'd recommend that you use Linear Layouts with nested Linear Layouts and weights, for better performance on different screens and devices. This may all fall apart if you run it on a different device. Don't trust me, try it :)
After it became clear to me that some of the layout parameters didn't mean what I thought they did, I spent some more time looking at my choices.
It is not recommended to nest LinearLayouts/use layout_weight within a list item, as the number of views created increases rapidly as more items are added. I managed to minify my code and keep it in a single RelativeLayout with the following code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/conversation_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/activity_horizontal_margin">
<ImageView
android:id="#+id/conversation_contact_image"
android:layout_width="64dp"
android:layout_height="64dp"/>
<TextView
android:id="#+id/conversation_contact_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/conversations_contact_font_size"
android:layout_toEndOf="#id/conversation_contact_image"/>
<TextView
android:id="#+id/conversation_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignBaseline="#id/conversation_contact_name"
android:textSize="#dimen/conversations_date_font_size"/>
<TextView
android:id="#+id/conversation_snippet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/conversation_contact_name"
android:textSize="#dimen/conversations_snippet_font_size"
android:layout_toEndOf="#id/conversation_contact_image"/>
</RelativeLayout>
Notable changes:
No nested tags - It was unnecessary to group the first line in its own layout
Used layout_alignBaseline - #Vucko pointed out that I was using marginTop on the contact name but not the date. Even after removing it, the two were still misaligned. android:gravity had no effect and it turns out none of these actually affect the text inside the layout
Used layout_alignParentEnd to fix the date issue. I've realized that in my case, a layout component usually only needs to reference one other in order to properly align itself relative to the rest of the layout.

AutoCompleteTextView suggestions clips the textview

I have implemented a custom Adapter for my AutoCompleteTextView along with a custom list item view for the suggestions. Everything works except the suggestions dialog clips the suggestions. This is most likely caused by the fact that the textview is multiline but I can't figure out how to tell the suggestions popup to expand to fill the entire view. Here is my code for the view:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="none"
android:textColor="#android:color/black"
android:textSize="15dp"
android:padding="10dp" />
</RelativeLayout>
Here is an image to what it looks like:
I also noticed that it doesn't clip if the android version is higher, I am testing on 2.3.5 and it clips (my phone) but on 4.1 (emulator) it looks fine.
Anyone know how to fix this?

Categories

Resources