安卓用代碼生成控件的方法

一般控件:

private TextView getTextView()
{
   AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
         ViewGroup.LayoutParams.MATCH_PARENT, 64);
   TextView textView = new TextView(MainActivity.
         this);
   textView.setLayoutParams(lp);
   textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
   textView.setPadding(36, 0, 0, 0);
   textView.setTextSize(20);
   return textView;
}

內容控件:

public View getGroupView()
{
   LinearLayout ll = new LinearLayout(
         MainActivity.this);
   ll.setOrientation(LinearLayout.HORIZONTAL);
   ImageView logo = new ImageView(
         MainActivity.this);
   logo.setImageResource(logos[groupPosition]);
   ll.addView(logo);
   TextView textView = getTextView();
   textView.setText(getGroup(groupPosition).toString());
   ll.addView(textView);
   return ll;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章