Foreground Drawable不包括整个视图

时间:2015-08-28 19:48:34

标签: android view android-framelayout colordrawable

我正在使用FrameLayout前景ColorDrawable。大部分时间它工作正常,但偶尔颜色不会填满整个View。它似乎记住了其他观点的高度。

这是一个证明问题的例子。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);
    Random random = new Random();
    final List<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < 50; i++)
        list.add(50 + random.nextInt(150));
    final Drawable blue = new ColorDrawable(Color.BLUE);
    ListView listView = (ListView) findViewById(R.id.list_view);
    listView.setAdapter(new ArrayAdapter<Integer>(this, -1, list) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            FrameLayout frameLayout;
            TextView textView;
            if (convertView == null) {
                frameLayout = (FrameLayout) getLayoutInflater().inflate(R.layout.item, parent, false);
                textView = new TextView(MyActivity.this);
                frameLayout.addView(textView);
            } else {
                frameLayout = (FrameLayout) convertView;
                textView = (TextView) frameLayout.getChildAt(0);
            }
            textView.setHeight(list.get(position));
            frameLayout.setForeground(blue);
            return frameLayout;
        }
    });
}

我认为蓝色块之间的唯一间隙应该是ListView分隔线,但偶尔会出现更大的间隙,如下所示。谁能解释一下呢?

enter image description here

0 个答案:

没有答案