RelativeLayout add rule “RelativeLayout.LEFT_OF” not working

前端 未结 6 1217
小蘑菇
小蘑菇 2020-12-17 10:50

I have a relativeLayout like below:



        
6条回答
  •  隐瞒了意图╮
    2020-12-17 11:30

    If your variable names are indicative, it's because you are adding the widget to a LinearLayout, so tags for a RelativeLayout get ignored.

    This line is the one I'm talking about:

    m_linearLayout.addView(button2, layoutParams);
    

    EDIT

    You say alignParentRight works... the only difference there is that ot doesn't take an anchor parameter. Perhaps m_listView.getId() isn't returning the proper id. You could step through with the debugger and see if it's returning a proper value.

    Maybe you could try calling the id specifically...

    layoutParams.addRule(RelativeLayout.LEFT_OF, R.id.list);
    

提交回复
热议问题