DB からいくつかのデータを取得しており、それを箇条書きリストの形式で表示する必要があります。
コードで:
for (int i=0; i<ingredcount; i++){
String ingredient = recipe.Ingredients.get(i);
View linearlayout = findViewById(R.id.llIngredients);
ImageView img = new ImageView(RecipeIngredientsDisplay.this);
TextView txt1 = new TextView(RecipeIngredientsDisplay.this);
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
llp.setMargins(30, 2, 15, 2);
LinearLayout.LayoutParams llp2 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
llp2.setMargins(10, 2, 15, 2);
img.setLayoutParams(llp2);
img.setImageResource(R.drawable.dot_purple);
txt1.setLayoutParams(llp);
txt1.setText(ingredient);
((LinearLayout)linearlayout).addView(img);
((LinearLayout) linearlayout).addView(txt1);
}
すべてのデータが正しく表示されています。画像が新しい行にあり、テキストがその下にあるだけです。
したがって、プログラムで画像とテキストに重みを設定して、両方が 1 行に収まるようにしたいと思います。
通常、アダプターとインフレータブル listView を使用してこれを行いますが、ScrollView 内で scrollView と ListView を組み合わせるとうまく動作せず、多くの成分があるとフォーカスが失われます。