我有一个Flow布局,显示行的4个对象,但我需要显示这些4个对象,每个对象下面都有一个textview。但它显示2图像和2 textview,并junp到另一行。我尝试创建一个ViewGroup以将它们一起显示,但我得到了相同的结论。也许如果我尝试设置组内的textView的位置它运河工作,但我不知道如何做到这一点。创建ViewGroup的ImageView和TextView,并以编程方式在FlowLayout中显示它 - Android
我的XML:
<ScrollView
android:id="@+id/svLikes"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="60dp"
android:layout_marginEnd="14dp"
android:layout_marginStart="14dp"
android:layout_marginTop="48dp"
android:background="#3c4052"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/btnAdd"
app:layout_constraintVertical_bias="0.0"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1">
<com.nex3z.flowlayout.FlowLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingRight="5dp"
app:childSpacingForLastRow="align"
android:paddingLeft="5dp"
app:rowSpacing="8dp"
android:id="@+id/likesContainer"
>
</com.nex3z.flowlayout.FlowLayout>
</ScrollView>
我的代码:
ImageView iconLike = new ImageView(Register30.this);
TextView txtLike = new TextView(Register30.this);
iconLike.setImageDrawable(getDrawable(R.drawable.x));
txtLike.setText("Unable");
countLikesAdd++;
removeMessageOrShow();
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(140,130);
lp.setMargins(5,5,5,5);
iconLike.setLayoutParams(lp);
txtLike.setLayoutParams(lp);
txtLike.setTextColor(Color.parseColor("#FFFFFF"));
fieldLike.setText("");
ViewGroup gp = new LinearLayout(Register30.this);
gp.addView(iconLike);
gp.addView(txtLike);
likesContainer.addView(gp);
你想只使用flowlayout库所需的效果? –
对不起。我没有得到它...我想flowlayout认为imageview和textView只是一个obj。 – Adolfok3
如果你有固定数量的项目定义你的布局在XML或如果动态使用gridview –