0

I've got a Customer Spinner with images inside of it. Right now everything is working as intented except for two small things:

  1. The Spinner is not showing except for a small thin line.
  2. The Spinner Items gray border extends a bit.

I've added screenshots of these problems below:

enter image description hereenter image description here

What I want is:

  1. Instead of the small thin line above, I want an empty CheckBox-image like the one below it.
  2. At the right of the images of the Spinner items is a gray part, this should be removed.

I know both of these problems are in the xml files, but I'm kinda new to Android and I'm always a bit confused with which layout_widht/height to use when.

Here are the xml files:

activity_main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context="com.example.testproject.MainActivity$PlaceholderFragment" >

    <Spinner 
        android:id="@+id/spCheckbox"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="15dp"
        android:drawSelectorOnTop="true" />

    <ImageButton
            android:id="@+id/ibtnCheckbox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dp"
            android:contentDescription="@string/checkbox_content_description"
            android:src="@drawable/checkbox_unchecked"
            android:background="@drawable/transparent_background" />

</LinearLayout>

spinner_item.xml:

<?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">

    <ImageView
        android:id="@+id/cbImage"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:background="@drawable/transparent_button_background" />

</RelativeLayout>

(transparent_background.xml:)

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:drawable="@android:color/transparent" />
    <item android:state_pressed="true" android:drawable="@android:color/transparent" />
    <item android:drawable="@android:color/transparent" />
</selector>

So.. Which layout_width / layout_height do I need to change to get the proper results?

Thanks in advance for the responses.

EDIT: I did some research and I started by replacing all fill_parent with match_parent (since it's the same and fill_parent is deprecated after API lvl. 8). For my problem it seems my activity_main layout should be match_parent to be fullscreen and the Spinner, Spinner Item's Layout and Spinner Item's ImageView should all be wrap_content.

Still, if I change it to that, both problems still remain the same. If anyone knows how to display the selected Image of the Spinner and how to remove the gray spacing of the Spinner item, let me know.

Kevin Cruijssen
  • 9,153
  • 9
  • 61
  • 135

1 Answers1

0

The problem of the thin line instead of the Spinner is solved.. It turns out when I was following a tutorial somewhere on the internet they added the line:

spinner.getLayoutParams().width = 3;

Removing this line, obviously, fixed the first problem.. >.> (No idea why they've added this in the first place too be honest, but now that it's gone I see my spinner as normal)

Now I just need to fix the second problem of the gray borders, but I'm sure I'll find a solution eventually..

EDIT: Since I wanted to remove the spinner right-bottom arrow in addition to the gray padding, I decided to remove the Spinner entirely and create a Pop-up with a LineairLayout which has a vertical orientation.

For a reference to the code, I posted it in another question of mine.

Community
  • 1
  • 1
Kevin Cruijssen
  • 9,153
  • 9
  • 61
  • 135