我面临着在排列文本视图时的问题,我是在一个线性布局的水平视图中动态创建芯片,当我创建多个芯片时,只有少数芯片正在查看,其余的都是隐藏的,当第一行是filled.Please时,如何在第二行排列芯片帮助我如何解决这个问题。
下面的代码用于动态创建线性布局的芯片
LinearLayout linearChip = (LinearLayout)findViewById(R.id.linear_chip);
Chip chip = new Chip(this);
chip.setChipText(tag);
chip.setClosable(true);
chip.setPadding(10,0,0,0);
chip.setTextColor(Color.BLACK);
chip.setBackgroundColor(Color.LTGRAY);
chip.setCloseColor(Color.BLACK);
chip.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
chip.setOnCloseClickListener(new OnCloseClickListener() {
@Override
public void onCloseClick(View v) {
linearChip.removeView((View) v.getParent());
}
});
linearChip.addView(chip);}
发布于 2017-04-04 19:42:42
请检查此FlowLayout Library 。
在添加视图时,FlowLayout的工作方式与预期一样,如果在FlowLayout中添加视图,它将自动调整视图。
<com.FlowLayout
android:id="@+id/chips_box_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="start"/>FlowLayout chipsBoxLayout = (FlowLayout)findViewById(R.id.chips_box_layout);
FlowLayout.LayoutParams params = new FlowLayout.LayoutParams(FlowLayout.LayoutParams.WRAP_CONTENT, FlowLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(5, 5, 5, 5);
String demoText;
for(int i=0; i< 5; i++){
demoText = "hello" + i;
TextView t = new TextView(context);
t.setLayoutParams(params);
t.setPadding(5, 5, 5, 5);
t.setText(demoText);
t.setTextColor(Color.WHITE);
t.setBackgroundColor(Color.BLUE);
chipsBoxLayout.addView(t);
}https://stackoverflow.com/questions/43205843
复制相似问题