刚才用相对布局的时候,需要用到子控件水平平分父控件的容器。可是在百度上找了半天没有什么可行的办法,所以就自己研究了下。现在我发现了一种比较麻烦的方法,不过能解决问题也算可以了,如果有朋友有更好的方法,希望不吝告诉下。好了,我所说的方法就是,在两个 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>
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
分享文章:android相对布局水平平分父控件容器-创新互联
网页路径:https://www.cdcxhl.com/article14/dgdide.html
成都网站建设公司_创新互联,为您提供App开发、商城网站、网站排名、做网站、营销型网站建设、电子商务
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联