change position of spinner dropdown list

北城余情 提交于 2021-01-26 23:48:28

问题


I need to change the horisontal position of Spinner's dropdown list. here's the screenshot :

enter image description here

and I want this dropdown list to go in one line under the main icon/text so it would look fine

As on the picture :

enter image description here

here's what I do in xml :

<Spinner
    android:id="@+id/tvHeader"
    style="@style/spinner_style"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/ver_main_donate_background_tile_long"
    android:layout_alignTop="@+id/ver_main_donate_background_tile_long"
    android:layout_marginTop="5dp"
    android:layout_toRightOf="@+id/icon_main_header"
    android:spinnerMode="dropdown"
    android:dropDownHorizontalOffset="-15dp"
    android:gravity="left|center_vertical"

    android:text="@string/name_of_product" />

so, as I suppose,

android:spinnerMode="dropdown"
android:dropDownHorizontalOffset="-15dp"

should do the trick, but as you see on the screenshot it doesn't work


回答1:


enter image description here

You can observe that the list items are aligned slight right, from the parent So i added a marginLeft attribute in spinner view

android:layout_marginLeft="20dp"

and thats worked for me, below you can see the difference

enter image description here




回答2:


You could just make the Spinner without the triangle.

First, create a styles.xml file under res/values, open it and add the following:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style parent="@android:style/Widget.Spinner" 
name="SpinnerAsEditText"><item 
name="android:background">@android:drawable/edit_text</item>
</style>
</resources>

Next, in your layout, add the Spinner like this:

<Spinner style="@style/SpinnerAsEditText" anyOtherAttributeYouNeed="..."></Spinner>

When you use it like this you Spinner will look just like a EditText without the little triangle.




回答3:


Use this to make the button as you want

    getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
    getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));   
    getSupportActionBar().setCustomView(R.layout.custom_actionbar);

And this is the costume layout

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center|right"
    android:paddingBottom="3dp"
    android:paddingLeft="3dp"
    android:paddingRight="-6dp"
    android:paddingTop="3dp"
    android:src="@drawable/ic_launcher" />

<Button
    android:id="@+id/mytext"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:gravity="left|center"
    android:text="wheresmyTURF"
    android:textColor="#ffff"
    android:textSize="26sp"
    app:customTypeface="fonts/pompiere.ttf" />

by this you customize the action bar so you can make some changes as you need i think....



来源:https://stackoverflow.com/questions/23610810/change-position-of-spinner-dropdown-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!