本文介绍了做微调尺寸更大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尽量让微调与字体大小。例如:小,大,了最重要的
现在我的微调布局如下:

I try to make spinner with font sizes. For example: small, BIGGER, THE BIGGEST. Now my layout for spinner looks like:

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


在一个尺寸的打印文本(小,大,最大的)。
我如何能在飞旋的每一个元素增加字体大小?

and print text in one size (small, big, the biggest).How can I increase font size in every element of the spinner?

推荐答案

我认为你需要这样。我已经做了一个示范项目,对于这个问题

I Think you need like this. I have made one demo project for this problem

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>

这篇关于做微调尺寸更大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 20:59