【发布时间】:2017-07-24 22:50:53
【问题描述】:
我有一个 Flow 布局,显示 4 个对象的行,但我需要显示这 4 个对象,每个对象下方都有一个文本视图。但它显示 2 个图像和 2 个文本视图,并跳转到另一行。我尝试创建一个 ViewGroup 将它们一起显示,但我遇到了同样的问题。也许如果我尝试在组内设置 textView 的位置它可以工作,但我不知道该怎么做。
我的 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。
-
如果你有固定数量的项目在xml中定义你的布局或者如果动态使用gridview
-
我没有固定数量的 obj 要添加。可以通过编程方式添加。
标签: android android-linearlayout android-relativelayout viewgroup flowlayout