android百分比布局

糖醋咸鱼 2017-09-17 09:24:09
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
android:id="@+id/button1"
android:text="button1"
android:layout_gravity="left|top"
app:layout_heightPercent="50%"
app:layout_widthPercent="50%" />
<Button
android:id="@+id/button2"
android:text="button2"
android:layout_gravity="right|top"
app:layout_heightPercent="50%"
app:layout_widthPercent="50%" />
<Button
android:id="@+id/button3"
android:text="button3"
android:layout_gravity="left|bottom"
app:layout_heightPercent="50%"
app:layout_widthPercent="50%" />
</android.support.percent.PercentRelativeLayout>
这样写为什么全部按钮都在左上角?
...全文
239 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
江三木洛 2017-09-18
  • 打赏
  • 举报
回复
android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" 用这个属性
jklwan 2017-09-18
  • 打赏
  • 举报
回复
RelativeLayout是相对布局,没有margin也没有below之类的,当然都在左上角了。
rayw0ng 2017-09-18
  • 打赏
  • 举报
回复
建议用 ConstrainLayout
smile_邝野 2017-09-18
  • 打赏
  • 举报
回复
PercentRelativeLayout你用个相对布局,在没有指定相对的是哪个时默认都是相对父容器的,

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧