我正在開發一個應用程序,在其中我需要將徽標左對齊,然後選擇右側的類別列表。因此,我所擁有的是圖像視圖中的標誌,它位於線性佈局中,然後向LinearLayout添加一個ListView,以便它們可以在同一個活動上。當我嘗試運行它時,出現意外停止的錯誤。帶Imageview和列表視圖的LinearLayout
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Commands.setText("Commands");
LinearLayout LL = new LinearLayout(this);
ImageView Logo = (ImageView)findViewById(0x7f020000);
Logo.setImageDrawable(getResources().getDrawable(android.R.drawable.ic_menu_myplaces));
ListView Cats = new ListView(this);
String Categories[] = new String[3];
Categories[0] = "Hardware";
Categories[1] = "Language";
Categories[2] = "Libraries";
ArrayAdapter<String> list = new ArrayAdapter<String>(this, 0, 2, Categories);
Cats.setAdapter(list);
LL.addView(Logo);
LL.addView(Cats);
setContentView(LL);
}
任何幫助,我真的很困惑