現在、Java コードでカスタム UI を作成したいと考えており、xml ファイルについて心配する必要はありません。linearLayout の既存の textView の下に textView を追加したいところです。これが私がこれまでに持っているものです。
View linearLayout = findViewById(R.id.rockLayout);
ImageView mineralPicture = new ImageView(this);
TextView mineralName = new TextView(this);
TextView mineralProperties = new TextView(this);
mineralProperties.setText("The properties are: " + Statics.rockTable.get(rockName).getDistinctProp());
mineralProperties.setId(2);
mineralName.setText("This mineral is: " + rockName);
mineralName.setId(1);
mineralName.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.MATCH_PARENT));
mineralProperties.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.MATCH_PARENT));
/** Need to figure out the picture....
* mineralPicture.setId(2);
* mineralPicture.setImageResource(R.drawable.rocks);
* mineralPicture.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
*/
((LinearLayout)linearLayout).addView(mineralName);
((LinearLayout)linearLayout).addView(mineralProperties);
問題は、mineralName textView のみを追加し、mineralProperties textView を追加しないことです。私はそれが一番上にあると思うので、ミネラル名のテキストビューを一番上に置き、次にミネラルプロパティのテキストビューをそのすぐ下に置きます。