[英]android spinner text size with layout.xml is not working
I have this layout 我有这个布局
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>
and in dialogfragment I have this code 在dialogfragment中,我有此代码
listado=DM.RegresaTiposCombustible();
adapter= new TiposCombustibleAdapter(getActivity(),R.layout.spinnertipocombustible,listado);
adapter.setDropDownViewResource(R.layout.spinnertipocombustible);
spinner.setAdapter(adapter);
in next picture you can see the text size which not change if I change this line in spinnertipocombustible.xml 在下一张图片中,您可以看到如果我在spinnertipocombustible.xml中更改此行,则文字大小不会改变
android:textSize="50dip"
this is my adapter.. 这是我的适配器。
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;
}
}
Try using 50sp
or 50dp
instead of 50dip
. 尝试使用
50sp
或50dp
而不是50dip
。 You might also want to try to change layout_height
to wrap_content
instead of a fixed value. 您可能还想尝试将
layout_height
更改为wrap_content
而不是固定值。
Take a look here . 在这里看看。 Available units for android:textSize are:
android:textSize的可用单位为:
Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).
可用的单位是:px(像素),dp(与密度无关的像素),sp(基于首选字体大小的缩放像素),(英寸),mm(毫米)。
So, instead of android:textSize="50dip" , use any acceptable unit (eg, dp or sp). 因此,请使用任何可接受的单位(例如dp或sp),而不是android:textSize =“ 50dip” 。
Instead of android:textSize="50dip"
, use any acceptable unit like dp
and sp
. 代替
android:textSize="50dip"
,使用任何可接受的单位,例如dp
和sp
。
Example 例
android:textSize="50dp"
android:textSize="50sp"
Dont use LinearLayout. 不要使用LinearLayout。 just remove that layout and increase your textsize.
只需删除该布局并增加您的文本大小即可。 It will work.
它会工作。
try this code...... Remove linearlayout from your textview and use it. 试试这个代码……从您的textview中删除linearlayout并使用它。
<?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"
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.