当我尝试在循环中添加充气机视图时,它彼此重叠,有没有我可以打破的两个列表。我想要这种视图
名称列表以及图片(1至4)
网格布局
名称列表以及图片(其余4个)
这是我尝试使用充气机时的代码。还有其他方法可以动态访问带有图像的名称并将其分为两部分
home.java
for (ParseObject object : objects) {
LinearLayout linear= new LinearLayout(getApplicationContext());
image = (ParseFile) object.get("image");
shopname.add(object.get("Name").toString());
shoptimings.add(object.get("timings").toString());
shopstatus.add(object.get("status").toString());
try {
Bitmap bitmap = BitmapFactory.decodeByteArray(image.getData(), 0, image.getData().length);
shopimageview.setImageBitmap(bitmap);
shopimage.add(bitmap);
} catch (ParseException e1) {
e1.printStackTrace();
}
shopnameview.setText(object.get("Name").toString());
shopstatusview.setText(object.get("status").toString());
shoptimingsview.setText(object.get("timings").toString());
final View myview=layoutinflater.inflate(R.layout.shopscroll,null,false);
linear.addView(myview);
root.addView(linear);
}
root.addView(myview);
Log.i("image", shopimage.toString());
}
shopscroll.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:padding="0dp"
android:layout_margin="0dp"
android:id="@+id/relativeLayout2">
<ImageView
android:id="@+id/shopimage"
android:layout_width="100dp"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher" />
<TextView
android:layout_width="40dp"
android:layout_height="30dp"
android:textSize="20sp"
android:id="@+id/shopstatus"
android:text="jjj"
android:layout_marginRight="30dp"
android:layout_alignBottom="@+id/shopimage"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
android:id="@+id/shopname"
android:text="fff"
android:layout_marginTop="13dp"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/shopimage"
android:layout_marginStart="17dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/shopimage"
android:textSize="18sp"
android:text="Timings:9 To 10"
android:layout_alignBottom="@+id/shopimage"
android:gravity="center"
android:id="@+id/timings"
android:layout_marginStart="17dp"
/>
</RelativeLayout>
</RelativeLayout>
我也尝试通过使用两个列表视图来使用列表视图,但是整个列表都显示在两个列表视图中
list = (ListView) findViewById(R.id.list);
final CustomAdapter customAdapter = new CustomAdapter();
list2 = (ListView) findViewById(R.id.list2);
final CustomAdapter customAdapter2 = new CustomAdapter();
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) {
for (ParseObject object : objects) {
LinearLayout linear= new LinearLayout(getApplicationContext());
image = (ParseFile) object.get("image");
shopname.add(object.get("Name").toString());
shoptimings.add(object.get("timings").toString());
shopstatus.add(object.get("status").toString());
try {
Bitmap bitmap = BitmapFactory.decodeByteArray(image.getData(), 0, image.getData().length);
shopimageview.setImageBitmap(bitmap);
shopimage.add(bitmap);
} catch (ParseException e1) {
e1.printStackTrace();
}
}
list.setAdapter(customAdapter);
list2.setAdapter(customAdapter2);
Log.i("image", shopimage.toString());
}
}
});
}
class CustomAdapter extends BaseAdapter {
@Override
public int getCount() {
return shopname.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (position < 3) {
convertView = getLayoutInflater().inflate(R.layout.shopscroll, null);
Log.i("list1 called", "getView: ");
TextView shopnametext = (TextView) convertView.findViewById(R.id.shopname);
TextView shopstatustext = (TextView) convertView.findViewById(R.id.shopstatus);
TextView shoptimingstext = (TextView) convertView.findViewById(R.id.timings);
ImageView image = (ImageView) convertView.findViewById(R.id.shopimage);
image.setImageBitmap(shopimage.get(position));
shopnametext.setText(shopname.get(position));
shopstatustext.setText(shopstatus.get(position));
return convertView;
} else {
return null;
}
}
}
class CustomAdapter2 extends BaseAdapter {
@Override
public int getCount() {
return shopname.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(position>2) {
convertView = getLayoutInflater().inflate(R.layout.shopscroll, null);
TextView shopnametext = (TextView) convertView.findViewById(R.id.shopname);
TextView shopstatustext = (TextView) convertView.findViewById(R.id.shopstatus);
TextView shoptimingstext = (TextView) convertView.findViewById(R.id.timings);
ImageView image = (ImageView) convertView.findViewById(R.id.shopimage);
image.setImageBitmap(shopimage.get(position));
shopnametext.setText(shopname.get(position));
shopstatustext.setText(shopstatus.get(position));
return convertView;
}else{return null;}
}
}