私は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));
}
}
アクティビティで次のようにアダプターを設定します。
ViewUtils.initListView(this, myListView, "Menu ", 5,
android.R.layout.simple_list_item_1);
「通知」テキストを「通知 n」のように設定します。ここで、n は上の写真の「2」のようなものです。スパン可能な文字列を使用しようとしましたが、スパン可能な文字列を文字列配列「arr」に設定できません
ありがとうございました