我從數據庫中提取一些數據,並且需要以子彈形式列表的形式顯示它。如何以編程方式在一行中同步Android imageView和textView
隨着代碼:
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);
}
我把所有的數據正確顯示,這只是我的形象是在新的生產線,和文字是婁它。
所以我想以編程方式將重量設置爲我的圖像和我的文本,以便它們都在一行中。
通常我使用適配器和充氣listView來做到這一點,但是scrollview和ListView在ScrollView中的組合運行並不好,當我有很多成分時,焦點會丟失。
爲什麼你不能只使用沒有ScrollView的ListView?如果需要,ListView自己處理滾動。 – Ralgha
因爲我有3個按鈕,頂部有一個文本視圖,所有內容都在滾動視圖中。正如上一句話所解釋的,如果我將所有內容都放在滾動視圖中,我無法將焦點放在列表的頂部,但它總是會出現在一些奇怪的位置......看起來很糟糕。 – Balkyto