在我的申请中,我有2个搜索栏。错误是他们在彼此!我只是不能在屏幕的所有宽度上将它们彼此相邻放置!他们是左边的!我希望一个向右对齐,一个向右对齐!
代码是:
public View wrapLabelAndSeekbar(String labelText, int width)
{
RelativeLayout layout = new RelativeLayout(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(250, 250);
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); // Doesn't work
seekerWidth = new SeekBar(this);
seekerHeight = new SeekBar(this);
seekerWidth.setProgress(Main.seekerPlaceWidth);
seekerHeight.setProgress(Main.seekerPlacHeight);
layout.addView(seekerHeight, params);
layout.addView(seekerWidth, params);
return layout;
}
我只能将其大小更改为屏幕的一半。没有了。
我该怎么办?
答案 0 :(得分:1)
一个小错误,像往常一样......显然......我只是把屏幕的宽度分成了两个,所以所有的都在同一个位置......
答案 1 :(得分:0)
RelativeLayout ll = new RelativeLayout(this);
ll.setId(99);
seekerWidth = new SeekBar(this);
seekerHeight = new SeekBar(this);
seekerWidth.setProgress(Main.seekerPlaceWidth);
seekerHeight.setProgress(Main.seekerPlacHeight);
seekerWidth.setId(1);
seekerHeight.setId(2);
RelativeLayout.LayoutParams lay = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lay.addRule(RelativeLayout.ALIGN_PARENT_TOP);
ll.addView(seekerWidth, lay);
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
p.addRule(RelativeLayout.BELOW, seekerWidth.getId());
ll.addView(seekerHeight, p);