I want to add a LinearLayout for every item in my draw folder. This is my Code:
final float scale = MlgMainActivity.this.getResources().getDisplayMetrics().density;
LinearLayout ll = (LinearLayout)findViewById(R.id.ll);
Field[] sounds = R.raw.class.getFields();
for(int i = 0; i < sounds.length; i++) {
LinearLayout layoutVertical = new LinearLayout(this);
layoutVertical.setOrientation(LinearLayout.VERTICAL);
layoutVertical.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, (int) (60 * scale + 0.5f)));
layoutVertical.setBackgroundColor((Color.parseColor("#000000")));
ll.addView(layoutVertical);
LinearLayout layoutHorizontal1 = new LinearLayout(this);
layoutHorizontal1.setOrientation(LinearLayout.HORIZONTAL);
layoutHorizontal1.setLayoutParams(new LinearLayout.LayoutParams((int)(MlgMainActivity.this.getResources().getDisplayMetrics().widthPixels * 0.65), LinearLayout.LayoutParams.FILL_PARENT));
layoutHorizontal1.setBackgroundColor((Color.parseColor("#ffffff")));
layoutVertical.addView(layoutHorizontal1);
TextView test = new TextView(this);
test.setText(String.valueOf(sounds[i].getName()));
test.setTextAppearance(this, R.style.TextAppearance_AppCompat_Large);
layoutHorizontal1.addView(test);
}
sounds.length is 4 but it only shows the first item and only adds one LinearLayout.
Maybe someone here has an idea?
0 comments:
Post a Comment