Android RelativeLayout并不适合视图中的所有内容

Android RelativeLayout并不适合视图中的所有内容,android,android-layout,android-relativelayout,Android,Android Layout,Android Relativelayout,在尝试将SeekBar添加到对话框时,我意识到我需要一个TextView来反映SeekBar的setProgress()。我是这样实施的: private void customDialogTimeout() { LinearLayout ll = new LinearLayout(getSherlockActivity()); ll.setOrientation(LinearLayout.VERTICAL); RelativeLayout input = ne

在尝试将
SeekBar
添加到对话框时,我意识到我需要一个
TextView
来反映
SeekBar
setProgress()
。我是这样实施的:

    private void customDialogTimeout() {
    LinearLayout ll = new LinearLayout(getSherlockActivity());
    ll.setOrientation(LinearLayout.VERTICAL);

    RelativeLayout input = new RelativeLayout(getSherlockActivity());

    final SeekBar timeoutSeekBar = new SeekBar(getSherlockActivity());
    timeoutSeekBar.setId(1);
    final TextView seekBarStatus = new TextView(getSherlockActivity());
    seekBarStatus.setId(2);

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
         LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams lay1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    lay1.addRule(RelativeLayout.CENTER_VERTICAL);
    lay1.addRule(RelativeLayout.ALIGN_PARENT_LEFT);

    RelativeLayout.LayoutParams lay2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    lay2.addRule(RelativeLayout.CENTER_VERTICAL);
    lay2.addRule(RelativeLayout.RIGHT_OF, timeoutSeekBar.getId());

    layoutParams.setMargins(30, 20, 30, 0);

    input.addView(timeoutSeekBar,lay1);
    input.addView(seekBarStatus, lay2);

    ll.addView(input, layoutParams);
然而,结果视图似乎“推出”了
TextView


我做错了什么?如果我用了错误的方法,请告诉我。

您的
SeekBar
的宽度设置为
RelativeLayout.LayoutParams.MATCH\u PARENT
并且当您将
TextView
添加到其左侧时,它显然不会显示,因为它被推出屏幕(因为
SeekBar
已经填充了整个宽度):

    RelativeLayout.LayoutParams lay1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    lay1.addRule(RelativeLayout.CENTER_VERTICAL);
    lay1.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    lay1.addRule(RelativeLayout.LEFT_OF, seekBarStatus.getId());

    RelativeLayout.LayoutParams lay2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    lay2.addRule(RelativeLayout.CENTER_VERTICAL);
    lay2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

    layoutParams.setMargins(30, 20, 30, 0);
    input.addView(seekBarStatus, lay2);
    input.addView(timeoutSeekBar,lay1);