0

在我的应用程序中,我有 2 个搜索栏。错误是他们在彼此身上!我只是不能将它们 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;
}

我只能将它们的大小更改为屏幕的一半。不再。

我能做些什么?

4

2 回答 2

1

一个小错误,像往常一样......显然......我只是将屏幕的宽度一分为二,所以所有的都在同一个位置......

于 2013-06-21T08:05:12.710 回答
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);
于 2013-06-13T10:15:41.053 回答