увеличить размер спиннера

Я пытаюсь сделать счетчик с размерами шрифта. Например: маленький, БОЛЬШОЙ, САМЫЙ БОЛЬШОЙ. Теперь мой макет для счетчика выглядит так:

<?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="match_parent" android:id="@+id/fontsizes_textview"
    android:layout_weight="0.5"
    android:textSize="25sp" />

и печатать текст одного размера (маленький, большой, самый большой). Как увеличить размер шрифта в каждом элементе счетчика?


person user3504091    schedule 27.03.2015    source источник
comment
Не могли бы вы показать код, в котором вы создаете свой SpinnerAdapter?   -  person joao2fast4u    schedule 27.03.2015


Ответы (1)


Я думаю, вам нужно, как это. Я сделал один демонстрационный проект для этой проблемы

введите здесь описание изображения

MainActivity.java

public class MainActivity extends ActionBarActivity {


    Spinner sp;
    spinnerAdapter spAdapter;



    String[] strText = { "small", "BIGGER", "THE BIGGEST" };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        sp = (Spinner) findViewById(R.id.spinner1);



        spAdapter = new spinnerAdapter(this, R.layout.spinner_row, strText);
        spAdapter.setDropDownViewResource(android.R.layout.simple_list_item_1);
        sp.setAdapter(spAdapter);


    }
}

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

spinnerAdapter.java

public class spinnerAdapter extends ArrayAdapter<Object> {

    private Context context;
    int resId;
    private String[] mAnimListItems;

    public spinnerAdapter(Context context, int textViewResourceId,
            String[] strText) {
        super(context, textViewResourceId, strText);
        this.resId = textViewResourceId;
        this.context = context;
        this.mAnimListItems = strText;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater mInflater = (LayoutInflater) context
                    .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            convertView = mInflater.inflate(resId, null);
        }

        TextView tv = (TextView) convertView.findViewById(R.id.tvItem);
        if (position == 0) {
            tv.setTextSize(25f);
        } else if (position == 1) {
            tv.setTextSize(35f);
        } else if (position == 1) {
            tv.setTextSize(40f);
        }

        tv.setText(mAnimListItems[position].toString());

        return convertView;
    }
}

spinner_row.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="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tvItem"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />

</LinearLayout>
person Darsh Patel    schedule 27.03.2015
comment
Это не работает. Часть метки больше, но все элементы в списке имеют размер шрифта по умолчанию. - person Gerry; 12.04.2015
comment
Фактическое решение: stackoverflow.com/ вопросы/10409871/ - person Gerry; 12.04.2015