使微调器尺寸更大
make spinner size bigger
我尝试制作带有字体大小的微调器。例如:小,更大,最大。
现在我的微调器布局如下:
<?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" />
并以一种尺寸(小、大、最大)打印文本。
如何增加微调器每个元素的字体大小?
我认为你需要这样的。我已经为这个问题做了一个演示项目
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>
我尝试制作带有字体大小的微调器。例如:小,更大,最大。 现在我的微调器布局如下:
<?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" />
并以一种尺寸(小、大、最大)打印文本。 如何增加微调器每个元素的字体大小?
我认为你需要这样的。我已经为这个问题做了一个演示项目
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>