android RelativeLayout, equal spacing?

北慕城南 提交于 2019-12-01 16:13:26

If you want equal spacing, you do not want a RelativeLayout. Use a LinearLayout, as you suggest in your question. If needed, put the Buttons in a LinearLayout and put the LinearLayout in the RelativeLayout.

The easiest would be to manipulate the view during OnCreate().

Something like:

OnCreate(Context ctx){
  int w = getWidth();
  int h = getHeight();
  Button B1 = findViewById(R.id.button1);
  B1.setWidth(w/3);
  --repeat for button2,3 textview--
}

Another option would be to use a TableLayout where you stretch the columns and force the buttons to fill parent. This would require you to use

<TableLayout    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="0,1,2"
    android:layout_below="@+id/textView"> 
<TableRow><Button
android:id="@+id/button1"
android:text="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/><Button
android:id="@+id/button2"
android:text="2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</TableRow>
</TableLayout>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!