我有一个RelativeLayout的象下面这样:的RelativeLayout添加规则“RelativeLayout.LEFT_OF”不工作
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:id="@+id/parent" >
<ListView
android:layout_width="360dp"
android:layout_height="600dp"
android:id="@+id/list"
android:inputType="text"
android:maxLines="1"
android:layout_margin="50dp"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
在Java代码中,我想一个视图添加到列表视图的左侧,但是事实并非如此工作:
m_relativeLayout = (RelativeLayout)findViewById(R.id.parent);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.LEFT_OF, m_listView.getId());
Button button2 = new Button(this);
button2.setText("I am button 2");
m_relativeLayout.addView(button2, layoutParams);
只有当我的列表视图设置为alignParentRight,它会工作。这是一个android bug或我错过了什么?
我总是尝试addView(View child, int index, LayoutParams params)
,但它可能只适用于线性布局。那么是否有正常的解决方案来使RelativeLayout.LEFT_OF
工作?
编辑
我试图RelativeLayout.BELOW
和RelativeLayout.RIGHT_OF
,并且他们的工作完美,所以这意味着我没有足够的地方,以获得该按钮?我试图给更多的空间,但它仍然无法工作。
我使用东芝AT100(1280 * 800)和风景,所以空间够了。测试below
和right
与left
相同。我想如果我把控件A放在相关布局中,那么我将控件B和控件A添加到控件A的左边,结果应该是控件B将控件A推向右边,对吧?
视图在哪里出现? – Barak
relativelayout是活动的主视图,它具有添加按钮的空间。 – dreamtale
我的意思是,按钮是不是出现,或出现在不适当的地方? – Barak