2025年Android组件到父容器距离,android 相对布局 水平平分父控件容器

Android组件到父容器距离,android 相对布局 水平平分父控件容器刚才用相对布局的时候 需要用到子控件水平平分父控件的容器 可是在百度上找了半天没有什么可行的办法 所以就自己研究了下 现在我发现了一种比较麻烦的方法 不过能解决问题也算可以了 如果有朋友有更好的方法 希望不吝告诉下 好了 我所说的方法就是 在两个 button 中间 再放一个 textview

大家好,我是讯享网,很高兴认识大家。

刚才用相对布局的时候,需要用到子控件水平平分父控件的容器。可是在百度上找了半天没有什么可行的办法,所以就自己研究了下。现在我发现了一种比较麻烦的方法,不过能解决问题也算可以了,如果有朋友有更好的方法,希望不吝告诉下。好了,我所说的方法就是,在两个 button 中间 再放一个textview 或者其他什么的,只是用来作为一个中间位置参考的,将textView 设置水平居中(android:layout_centerHorizontal="true"),然后 分别将需要水平平分父容器的两个button 设置 android:layout_toLeftOf="@+id/textview "和android:layout_toRightOf="@+id/textview"属性,最后将两个button的宽度设置fill_parent 就行了。

下面是测试的布局代码:

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" >

android:id="@+id/ImageButton"

android:contentDescription="@+id/ImageButton"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="@string/hello_world" />

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="上传数据"

/>

android:id="@+id/cencer"

android:layout_width="0dip"

android:layout_height="wrap_content"

android:layout_below="@+id/ImageButton"

android:layout_centerHorizontal="true"

/>

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="添加数据"

/>

小讯
上一篇 2025-01-10 23:03
下一篇 2025-04-05 09:01

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/116857.html