【问题标题】:android spinner text size with layout.xml is not working带有layout.xml的android微调器文本大小不起作用
【发布时间】:2016-09-07 19:40:14
【问题描述】:

我有这个布局

spinnertipocombustible.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <TextView
        android:id="@+id/textview"
        android:layout_height="30dip"
        android:layout_width="wrap_content"
        android:textSize="50dip"
        android:textColor="#ccddaa"
        />
</LinearLayout>

在对话框片段中我有这段代码

listado=DM.RegresaTiposCombustible();
adapter= new TiposCombustibleAdapter(getActivity(),R.layout.spinnertipocombustible,listado);
adapter.setDropDownViewResource(R.layout.spinnertipocombustible);
spinner.setAdapter(adapter);

在下一张图片中,您可以看到文字大小如果我更改则不会更改 spinnertipocombustible.xml 中的这一行

android:textSize="50dip"

这是我的适配器..

public class TiposCombustibleAdapter extends ArrayAdapter<TipoCombustible>{

    private Context context;

    private List<TipoCombustible> tipoCombustibles;

    public TiposCombustibleAdapter(Context context, int textViewResourceId, List<TipoCombustible> tiposCombustible){

        super(context,textViewResourceId,tiposCombustible);
        this.context=context;
        this.tipoCombustibles=tiposCombustible;

    }

    public  int getCount(){

        return  tipoCombustibles.size();
    }

    public TipoCombustible getItem(int position){
        return  tipoCombustibles.get(position);
    }

    public long getItemId(int position){
        return  position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // I created a dynamic TextView here, but you can reference your own  custom layout for each spinner item
        TextView label = new TextView(context);
        label.setTextColor(Color.BLACK);
        // Then you can get the current item using the values array (Users array) and the current position
        // You can NOW reference each method you has created in your bean object (User class)
        label.setText(tipoCombustibles.get(position).getDescripcion());

        // And finally return your dynamic (or custom) view for each spinner item
        return label;
    }

    @Override
    public View getDropDownView(int position, View convertView,
                                ViewGroup parent) {
        TextView label = new TextView(context);
        label.setTextColor(Color.BLACK);
        label.setText(tipoCombustibles.get(position).getDescripcion());

        return label;
    }


}

【问题讨论】:

    标签: android android-layout layout spinner android-spinner


    【解决方案1】:

    尝试使用50sp50dp 而不是50dip。您可能还想尝试将 layout_height 更改为 wrap_content 而不是固定值。

    【讨论】:

    • 我已将其更改为 500sp 并且大小未更改
    • 我已经添加了我的适配器,可能有错误但我没有看到它
    • 在适配器中执行此操作-> getview 大小更改 label.setTextSize(20);
    【解决方案2】:

    看看hereandroid:textSize 的可用单位是:

    可用单位有:px(像素)、dp(与密度无关的像素)、sp (基于首选字体大小的缩放像素),in(英寸),mm (毫米)。

    因此,不要使用 android:textSize="50dip",而是使用任何可接受的单位(例如 dp 或 sp)。

    【讨论】:

    • 我已经改变了 50dip 50 sp 和 500 sp 之后,文本大小没有改变
    • 我已经添加了我的适配器,可能有错误但我没有看到它
    • 在适配器中执行此操作-> getview 大小更改 label.setTextSize(20);
    【解决方案3】:

    不要使用android:textSize="50dip",而是使用任何可接受的单位,例如dpsp

    例子

    android:textSize="50dp"
    android:textSize="50sp"
    

    【讨论】:

      【解决方案4】:

      不要使用线性布局。只需删除该布局 并增加你的文本大小。它会起作用的。

      【讨论】:

        【解决方案5】:

        试试这个代码...... 从您的文本视图中删除线性布局并使用它。

        <?xml version="1.0" encoding="utf-8"?>
        <TextView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/textview"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:textSize="50dp"
            android:textColor="#ccddaa"
            />
        

        【讨论】:

          猜你喜欢
          • 2011-10-18
          • 1970-01-01
          • 1970-01-01
          • 2013-05-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多