我在xml中有LinearLayout:
android:id="@+id/progress"
android:layout_width="fill_parent"
android:layout_height="@dimen/progress_height"
android:layout_alignParentBottom="true"
android:baselineAligned="false"
android:orientation="horizontal" />
我想动态生成很少的另一个LinearLayouts并将它们等分为“进度”,例如:
>添加的第一个LinearLayout将占用所有空间.
>第二LL将与1LL共享50%的空间
>第三LL将分享33%的空间,1LL和2LL
>依此类推……
每个LinearLayout都有随机的背景颜色
我写了这样的东西:
mProgress = (LinearLayout) findViewById(R.id.progress);
.
.
.
LinearLayout prog = new LinearLayout(this);
prog.setBackgroundColor(CommonUtils.getNextRandomColor());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
prog.setLayoutParams(params);
mProgress.addView(prog);
当用户按下按钮时,将生成另一个LL,颜色不同.
我的方法不起作用.布局中没有背景颜色.
也许有另一种更简单的方法来实现某种进度条,颜色共享一些空间?