我尝试使用字体大小制作微调器。例如:小,大,最大。 现在我的微调框布局如下:
<?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" />
并以一种尺寸打印文本(小,大,最大)。 如何在微调器的每个元素中增加字体大小?
答案 0 :(得分:0)
我觉得你需要这样的。我为这个问题制作了一个演示项目
<强> 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>