Java 以编程方式创建一行不等的ImageView?
我不知道该怎么做。是否制作自定义阵列适配器或其他。这看起来很简单。对于每个个体,只需指定属性的数量 例如,我做了一个。我点击其中一个人查看他们有多少宠物/儿童/汽车: 所以对于其他人来说,它可能会像Java 以编程方式创建一行不等的ImageView?,java,android,Java,Android,我不知道该怎么做。是否制作自定义阵列适配器或其他。这看起来很简单。对于每个个体,只需指定属性的数量 例如,我做了一个。我点击其中一个人查看他们有多少宠物/儿童/汽车: 所以对于其他人来说,它可能会像 克里斯有三只宠物,一个小孩,一辆车 鲍比有0只宠物,0个孩子,1辆车 第三个人有6只宠物,5个孩子,2辆车 评级栏与我想做的类似,但它不能满足我的要求,因为所有图标的数量和图标本身都可能不同(汽车品牌、宠物种类、儿童性别),我不认为这是将其标记为重复的原因。因此,您的布局文件可能是这样的 &l
- 克里斯有三只宠物,一个小孩,一辆车
- 鲍比有0只宠物,0个孩子,1辆车
- 第三个人有6只宠物,5个孩子,2辆车
评级栏与我想做的类似,但它不能满足我的要求,因为所有图标的数量和图标本身都可能不同(汽车品牌、宠物种类、儿童性别),我不认为这是将其标记为重复的原因。因此,您的布局文件可能是这样的
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/pet_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"/>
<LinearLayout
android:id="@+id/kids_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" />
<LinearLayout
android:id="@+id/cars_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"/>
</LinearLayout>
这听起来像是一个列表模式……我支持@Chris的评论,但对于您的情况,因为每个人都被加载到一个活动中,这看起来也像一个滚动活动。您可以创建包含占位符视图的基本布局,最好是带有ID的线性布局。然后在代码中,为(pet:pets){petLinearLayout.addView(newimageview(this.setDrawable)(getResources().getDrawable(R.id.pet_drawable));}在这种情况下,宠物是一个列表,或者你可以使用传统的for循环和宠物的数量来获取建议。我必须研究列表列表,但是带有一些视图的线性布局听起来不错吧?
//After retrieving the data for say the person object
if(person.getPets().size()>0)
for(pet:pets){petLinearLayout.addView(new ImageView(this).setDrawable(getResources().getDrawable(R.id.pet_drawable));}
//Use similar code for children and cars