刚才用相对布局的时候,需要用到子控件水平平分父控件的容器。可是在百度上找了半天没有什么可行的办法,所以就自己研究了下。现在我发现了一种比较麻烦的方法,不过能解决问题也算可以了,如果有朋友有更好的方法,希望不吝告诉下。好了,我所说的方法就是,在两个 button 中间 再放一个textview 或者其他什么的,只是用来作为一个中间位置参考的,将textView 设置水平居中(android:layout_centerHorizontal="true"),然后 分别将需要水平平分父容器的两个button 设置 android:layout_toLeftOf="@+id/textview " 和 android:layout_toRightOf="@+id/textview " 属性,最后将两个button的宽度设置fill_parent 就行了。
下面是测试的布局代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.first_summary.MainActivity$PlaceholderFragment" >
<ImageButton
android:id="@+id/ImageButton"
android:contentDescription="@+id/ImageButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<Button
android:id="@+id/up"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/ImageButton"
android:layout_toLeftOf="@+id/cencer"
android:textSize="12sp"
android:text="上传数据"
/>
<TextView
android:id="@+id/cencer"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_below="@+id/ImageButton"
android:layout_centerHorizontal="true"
/>
<Button
android:id="@+id/add"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/ImageButton"
android:layout_toRightOf="@+id/cencer"
android:textSize="12sp"
android:text="添加数据"
/>
</RelativeLayout>
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。