Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:RelativeLayout.LEFT_的不起作用?_Android_Android Relativelayout - Fatal编程技术网

Android:RelativeLayout.LEFT_的不起作用?

Android:RelativeLayout.LEFT_的不起作用?,android,android-relativelayout,Android,Android Relativelayout,另一个我找不到答案的问题: 我有一个相对的图标,右边应该有一个按钮,左边应该有一个ImageButton。我不知道该怎么安排 我尝试的是: RelativeLayout TopLayout = (RelativeLayout) findViewById(R.id.topLayout); TopLayout.removeAllViews(); TopLayout.setPadding(m_TableRowPadding_px, 8, m_TableRowPadding_p

另一个我找不到答案的问题: 我有一个相对的图标,右边应该有一个按钮,左边应该有一个ImageButton。我不知道该怎么安排

我尝试的是:

    RelativeLayout TopLayout = (RelativeLayout) findViewById(R.id.topLayout);
    TopLayout.removeAllViews();
    TopLayout.setPadding(m_TableRowPadding_px, 8, m_TableRowPadding_px, 4);

    RelativeLayout.LayoutParams bParams = new RelativeLayout.LayoutParams(m_Resources
        .getDimensionPixelSize(R.dimen.ButtonWidth), m_DefaultButtonHeight_px);
    bParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    bParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);

    Button itemAddButton = new Button(this);
    itemAddButton.setLayoutParams(bParams);
    itemAddButton.setText(m_Resources.getString(R.string.add_item_button));
    itemAddButton.setOnClickListener(new View.OnClickListener()
    {...});

    TopLayout.addView(itemAddButton);

    RelativeLayout.LayoutParams ibParams = new RelativeLayout.LayoutParams(MIN_IMG_BUTTON_WIDTH,
        m_DefaultButtonHeight_px);
    ibParams.addRule(RelativeLayout.LEFT_OF, itemAddButton.getId());

    ImageButton speechButton = new ImageButton(this);

    speechButton.setLayoutParams(ibParams);
    speechButton.setContentDescription(m_Resources.getString(R.string.AddSpeechItemString));
    speechButton.setOnClickListener(new View.OnClickListener()
    {... });
    speechButton.setImageDrawable(m_Resources.getDrawable(R.drawable.micro2));

    TopLayout.addView(speechButton);

  }

但结果是右边有一个按钮(根据需要)和左边有一个ImageButton:(

有人能帮我吗

干杯


Chris

在使用该行之前,需要为itemAddButton按钮设置一个id。现在itemAddButton.getId()将只返回-1

ibParams.addRule(RelativeLayout.LEFT_OF, itemAddButton.getId());
你可以设置如下内容

itemAddButton.setId(5005000);

在使用该行之前,需要为itemAddButton按钮设置一个id。现在itemAddButton.getId()将只返回-1

ibParams.addRule(RelativeLayout.LEFT_OF, itemAddButton.getId());
你可以设置如下内容

itemAddButton.setId(5005000);

尝试将其他规则添加到您的
speechButton

ibParams.addRule(RelativeLayout.ALIGN_TOP, itemAddButton.getId());

如果这对您更合适,您也可以使用
RelativeLayout.ALIGN_BOTTOM

尝试向您的
语音按钮添加其他规则:

ibParams.addRule(RelativeLayout.ALIGN_TOP, itemAddButton.getId());
你也可以使用
RelativeLayout.ALIGN\u BOTTOM
,如果这样对你更合适的话。

谢谢:)从没想过,ID必须由程序员设置:(谢谢:)从没想过,ID必须由程序员设置:(