I have a custom spinner that uses two custom views, one for the drop down and one for the currently selected item.
My problem is, the custom view for the currently selected item is always at least as wide as the longest item in the spinner list and it leaves a sizeable gap on the left hand side of my custom view. If I select the longest item from the spinner, the gap disappears. I have tried android:gravity="left" for my custom view. Also note that this only seems to be an issue with Android 3.0+.
Here is the code for my custom spinner view:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="#+id/folder_detail" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="wrap_content">
<TextView android:text="Folder Name"
android:id="#+id/folder_name" android:textColor="#ffffff"
android:layout_width="wrap_content" android:textSize="16sp"
android:textStyle="bold"
android:layout_height="wrap_content" android:layout_marginTop="0dp">
</TextView>
<TextView android:id="#+id/folder_count" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="13sp" android:text="(0) " android:textColor="#color/light_blue" android:layout_marginLeft="2dp"/>
<ImageView android:id="#+id/icon" android:src="#android:drawable/arrow_down_float"
android:layout_marginRight="1dp" android:scaleType="fitXY"
android:layout_gravity="bottom" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</LinearLayout>
This is intentional. It prevents the spinner from drastically changing size as the selection changes.
You're not meant to include an arrow as part of the item view; this is normally included as part of the background 9-patch of the spinner itself. The gravity setting on the spinner itself controls the alignment of the selected item view within the spinner. The Holo theme aligns it to the left, while the legacy themes horizontally center.
Related
I have created an expandable listView where I am showing text side by side more likely I wanna show a table of 2 columns there. For that, I have used the expandable list view and so far it looks like this(The image below).
But I want to change the color of the first line of this list. something like this(image below).
As for code, I have used two text views in a horizontal Linear Layout and with a custom adapter I am showing the data in the view. here's the XML.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/itemText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:textSize="16sp"
android:text="item"/>
<TextView
android:id="#+id/itemText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:textSize="16sp"
android:text="Item2"/>
</LinearLayout>
Can anyone suggest what should I do to achieve this?
In your adapter if position = 0
itemText.setBackgroundColor(int colour);
Also you should use RecyclerView instead of ListView
I am trying to create a list view where every item in the list has an Image on top of a line of text. My problem is that I cannot get the Image to be any larger than 40X40, without it obscuring the view of the text underneath it. Here is my xml file:
<com.thinksai.saicloud.WearableListItemLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="center_vertical"
android:gravity="center_vertical">
<ImageView
android:id="#+id/image"
android:layout_height="40dp"
android:layout_margin="2dp"
android:layout_width="40dp"
android:adjustViewBounds="true"
android:src="#drawable/firefox"/>
<TextView
android:id="#+id/name"
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed-light"
android:textColor="#000003"
android:textSize="16sp"
android:layout_gravity="center_vertical"/>
<!--android:drawableTop="#drawable/firefox"/>-->
<!--android:drawablePadding="2dp"/>-->
</LinearLayout>
</com.thinksai.saicloud.WearableListItemLayout>
As you can see in the commented out lines of the Textview, I tried to use the "drawableTop" instead of the Imageview, but that didn't work either. The documentation for WearableListView.setMaximizeSingleItem (http://developer.android.com/reference/android/support/wearable/view/WearableListView.html) gives me the impression that Android Wear forces the list to show three items at a time, unless there is only one item in the list. Is this correct? Is there no work around to force the wear to show one item at a time, regardless of the number of items in the list?
NOTE: I don't set the text of the text view here in the xml, I do it programmatically.
I've got a ListView with a custom Adapter inheriting from ArrayAdapter. I'm using a custom Checkable subclass of LinearLayout to highlight the last selected item in the list where it basically maps the checked state to selected.
The layout used by the Adapter for list items is as follows:
<com.wordlistdictionary.CheckableLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="40dp">
<LinearLayout
android:id="#+id/entry_text"
android:layout_width="0dp"
android:layout_weight="7"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:duplicateParentState="true"
/>
<TextView
android:id="#+id/entry_number_of_occurences_1"
android:textSize="9pt"
android:typeface="monospace"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="#color/item_text_color_selector"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:duplicateParentState="true"
/>
<TextView
android:id="#+id/entry_frequency_1"
android:textSize="9pt"
android:typeface="monospace"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="#color/item_text_color_selector"
android:layout_gravity="center_vertical"
android:layout_weight="2"
android:duplicateParentState="true"/>
<ImageButton
android:id="#+id/delete_entry_button_1"
android:src="#drawable/delete_button_selector"
android:layout_height="40dp"
android:layout_width="40dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="15dp"
android:duplicateParentState="true"
/>
</com.wordlistdictionary.CheckableLinearLayout>
It works as I expect it with the text color changing for the last touched item until I'm adding the last ImageButton view and it stops highlighting the text from that point.
Has anybody encountered this and what was your solution?
Currently I'm thinking of a workaround with manually propagating the selected state to all child views from my custom layout as opposed to just changing the selected state of the layout view itself and relying on the duplicateParentState mechanism.
It turns out when added to a list item a Button or ImageButton "swallows" the touched event so it doesn't propagate to the list view so I had to set imageButton.setTouchable(false) in getView() in my custom Adapter.
Note that I first tried to set android:touchable='falase' in my layout file but it didn't work so I had to set it programmatically.
I've found the answer in these 2 SO questions:
ListView setOnItemClickListener not working by adding button
Click is not working on the Listitem Listview android
I try to create a stylish small width spinner in my Android application instead of default thick spinner.
I tried to change item's background but then downward arrow disappears from spinner - as on this image
How can I get small width spinner?
<Spinner
android:id="#+id/lgnspinner"
android:prompt="#string/network_prompt"
android:layout_weight="1"
android:layout_width="0dp"
android:background="#ffffff"
android:layout_marginRight="45dp"
android:layout_marginLeft="45dp"
android:layout_height="wrap_content"
android:textColor="#000000"
/>
Try this,
cityadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
i added background color of my layout, as white.
then i created a list by extending BaseAdapter class.
but my list item is not focusable(when i move cursor to any item it do not show focus color).
but if i remove background color tag of layout, it works fine.below is my xml layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:background="#color/color_white">
<ImageView
android:id="#+id/icon"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:visibility="visible" />
<TextView
android:id="#+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10px"
android:textColor="#color/color_white"
android:textSize="20dp"
android:visibility="visible" />
</LinearLayout>
please help.
The list item backgrounds are "State List Drawables", which define a color for different states of a view. If you set the background to just a simple color, it will be that color in all instances. You need to only override the specific "state" in the default drawable to keep the rest of the colors intact. Here's an example.