UzUmAkI_NaRuTo
UzUmAkI_NaRuTo

Reputation: 575

Spinner taking whole space below it in android activity

I am trying to make a xml activity as shown below in image in graphical layout.

Like in graphical layout shown on left

enter image description here


The spinner i made is taking whole space till the bottom of the activity due to which the button made disappears.

XML File:-

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:paddingBottom="2dp"
    android:paddingLeft="12dp"
    android:paddingRight="12dp"
    android:paddingTop="2dp"
    android:background="#FFFFFF"
    android:layout_height="match_parent" >

    <TextView
    android:id="@+id/select_project_chart"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="18dp"
    android:ems="10"
    android:text="Select Project To Rename"
    android:inputType="text"
    android:textAppearance="?android:attr/textAppearance"
    android:textColor="@android:color/black" />

    <Spinner
    android:id="@+id/spinner_for_rename"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/select_project_chart"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="103dp"
    android:animateLayoutChanges="true"
    android:prompt="@string/select_a_project"
    android:spinnerMode="dropdown" />

    <EditText
    android:id="@+id/new_name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/select_project_chart"
    android:layout_below="@+id/select_project_chart"
    android:layout_marginTop="32dp"
    android:ems="10"
    android:hint="New Name"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:theme="@style/EditTextsumeet" />

    <Button
    android:id="@+id/rename_pro"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/spinner_for_rename"
    android:layout_below="@+id/spinner_for_rename"
    android:layout_marginTop="98dp"
    android:background="@drawable/mybutton"
    android:gravity="center"
    android:paddingBottom="2dp"
    android:paddingLeft="12dp"
    android:paddingRight="12dp"
    android:paddingTop="2dp"
    android:text="Rename"
    android:textAppearance="?android:attr/textAppearanceMedium" />

    </RelativeLayout>

If i try to move button or the spinner it gives class cast exception error saying button cant be cast to spinner.

How to solve this ?

Upvotes: 1

Views: 1083

Answers (3)

RajeshVijayakumar
RajeshVijayakumar

Reputation: 10620

As your code tells that you had given android:layout_height="wrap_content" wrap_content will occupy space based on the drop down list item layout size...

So, for your drop down list item give specific height interms of "dp" like android:layout_height="65dp" and android:margin="3dp". It will solve your problem....

This solution for one screen size only. If you want to adjust the height and margin according to display, you have to implement multiple screen support for your app.

Use this for spinner Drop down item layout :

     <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/lbl_person_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:margin="5dp"
            android:layout_gravity="center_vertical"
            android:text="TextView" />
     </LinearLayout>

Upvotes: 0

Sarang
Sarang

Reputation: 83

For class cast exception, just clean the project before running.

Upvotes: 0

Fahim
Fahim

Reputation: 12368

As per your layout you have the control one below the order.. Use should use LinearLayout instead of RelativeLayout and this will fix ur problem also.

Upvotes: 1

Related Questions