我正在使用 Horizontal ScrollView 来获得像侧面导航一样的 facebook
像这样:
但是如何在菜单中的事件项旁边显示“2”?
在我的应用程序中,我使用 ViewUtil 类来获取此菜单:
public class ViewUtils {
private ViewUtils() {
}
public static void setViewWidths(View view, View[] views) {
int w = view.getWidth();
int h = view.getHeight();
for (int i = 0; i < views.length; i++) {
View v = views[i];
v.layout((i + 1) * w, 0, (i + 2) * w, h);
printView("view[" + i + "]", v);
}
}
public static void printView(String msg, View v) {
System.out.println(msg + "=" + v);
if (null == v) {
return;
}
System.out.print("[" + v.getLeft());
System.out.print(", " + v.getTop());
System.out.print(", w=" + v.getWidth());
System.out.println(", h=" + v.getHeight() + "]");
System.out.println("mw=" + v.getMeasuredWidth() + ", mh="
+ v.getMeasuredHeight());
System.out.println("scroll [" + v.getScrollX() + "," + v.getScrollY()
+ "]");
}
public static void initListView(Context context, ListView listView,
String prefix, int numItems, int layout) {
// By using setAdpater method in listview we an add string array in
// list.
String[] arr = new String[numItems];
arr[0] = "Feed";
arr[1] = "Friends";
arr[2] = "Notifications";
arr[3] = "Feedback";
arr[4] = "Logout";
listView.setAdapter(new ArrayAdapter<String>(context, layout, arr));
}
}
并在 Activity 中像这样设置适配器:
ViewUtils.initListView(this, myListView, "Menu ", 5,
android.R.layout.simple_list_item_1);
我的“通知”文本类似于“通知 n”,其中 n 类似于上图中的“2”。我尝试使用 Spannable String 但我无法将 Spannable String 设置为字符串数组“arr”
谢谢你