本文介绍了编程的LinearLayout - 如何建立一个除法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在的LinearLayout
创建 TextViews
编程,我想给他们一个分频器(只是一个简单的区分线)。我已经无数次用Google搜索,我发现的是,我可以用 .setDividerDrawable
,但我不希望使用外部图像这一点。
任何提示?
I am creating TextViews
in LinearLayout
programmatically and I would like to separate them with a divider (just a simple line). I have googled endlessly, what I have found is that I can use .setDividerDrawable
, but I don't want to use external images for this.Any tips?
推荐答案
创建一个查看
1或2像素高,宽度 match_parent
,并设置背景色为你想要的任何颜色分频器是。
How to Add Divider to an Android Layout Programmatically
Create a View
1 or 2 pixels tall and width match_parent
and set the background color to whatever color you want the divider to be.
分离从上面和下面的项目分压器保证金
设置。
Separate the divider from the items above and below with margin
settings.
示例
ImageView divider = new ImageView(this);
LinearLayout.LayoutParams lp =
new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lp.setMargins(left, top, right, bottom);
divider.setLayoutParams(lp);
divider.setBackgroundColor(Color.WHITE);
这篇关于编程的LinearLayout - 如何建立一个除法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!