我想要动态滚动条,从解析服务器中提取数据并将其添加到布局中。因此,我创建了动态线性布局,并在其中添加了文本视图和图像视图,除非我使用解析服务器,否则该视图可以正常工作。当我使用解析服务器时,我添加到文本视图和图像视图的属性未应用。 这是我的代码
LinearLayout root;
ParseFile image;
String shopnamestring;
root= (LinearLayout) findViewById(R.id.addshoplinearlayout);
ParseQuery<ParseObject> query= ParseQuery.getQuery("Shops");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if(e== null && objects.size()>0)
{int i=0;
for(ParseObject object: objects)
{
final ImageView shopimage []= new ImageView[objects.size()];
final TextView shopname[]= new TextView[objects.size()];
final LinearLayout child[] = new LinearLayout[objects.size()];
child[i]= new LinearLayout(getApplicationContext());
child[i].setOrientation(LinearLayout.VERTICAL);
ViewGroup.LayoutParams linearparams= new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
child[i].setLayoutParams(linearparams);
shopimage[i]=new ImageView(getApplicationContext());
shopname[i]= new TextView(getApplicationContext());
shopname[i].setGravity(Gravity.CENTER);
LinearLayout.LayoutParams nameparams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
image= (ParseFile)object.get("image");
shopnamestring= (String) object.get("Name");
shopname[i].setText(shopnamestring);
final int finalI = i;
image.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, ParseException e) {
Bitmap bitmap= BitmapFactory.decodeByteArray(data,0,data.length);
shopimage[finalI].setImageBitmap(bitmap);
}
});
shopimage[i].setMaxHeight(300);
shopimage[i].setMaxWidth(300);
LinearLayout.LayoutParams imageparams= new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
imageparams.setMargins(10,10,10,10);
shopimage[i].setLayoutParams(imageparams);
shopimage[i].setClickable(true);
child[i].addView(shopimage[i]);
child[i].addView(shopname[i]);
root.addView(child[i]);
i++;
}
}
}
});