現在、私はJavaのコードでカスタムUIを作成したいし、xmlファイルを心配したくありません。私は、私のlinearLayoutの既存のtextViewの下にtextViewを追加したいところにいます。ここに私がこれまで持っているものがあります。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);
問題は、mineralProperties textViewではなくmineralName textViewが追加されるということです。私はそれが非常に一番上にmineralName textView、それからmineralProperties textViewのすぐ下にしたいと思います。 LinearLayoutで