android-flowlayout
android-flowlayout copied to clipboard
draw children promblems
When add children dynamically with drawable , it doesn't work well
String[] gs = new String[]{"买车", "卖车", "订车", "车辆上牌", "车辆过户", "过户", "售后投诉处理"};
for (int i = 0; i < gs.length; i++) {
TextView textView = new TextView(this);
textView.setText(gs[i]);
FlowLayout.LayoutParams params = new FlowLayout.LayoutParams(FlowLayout.LayoutParams.WRAP_CONTENT,
FlowLayout.LayoutParams.MATCH_PARENT);
int m = DisplayUtil.dip2px(this, 10);
params.setMargins(m, m, m, m);
textView.setPadding(m, m, m, m);
textView.setGravity(Gravity.CENTER);
textView.setOnClickListener(goalListener);
textView.setBackground(gray);
System.out.println(gs[i] + " " + textView.getWidth());
goal.addView(textView, params);
}
<org.apmem.tools.layouts.FlowLayout
android:id="@+id/goal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="horizontal"
android:padding="15dp" />
Hi, sorry for late answer. I can not reproduce this issue now. Maybe it is already fixed, can you try latest commit. also if it is still exists can you send me your background xml? I have tried it with one I have found in internet: http://stackoverflow.com/questions/2122199/how-do-i-set-the-rounded-corner-radius-of-a-color-drawable-using-xml
and it looks ok with all 4 rounded borders.
I had the same problem as OP and found a solution.
The issue is not in FlowLayout but in the LinearLayout.
The only solution I found was to usesetBackgroundResource
instead of setBackground
and reference the ID of my background drawable.
@miquelbeltran Thanks a lot for the solution it worked in my case too. Can you please tell the logic behind it. I have seen the code but can't infer any substantial reason for it to work because it also uses the same setBackground
method within its implementation.