Android 百分比布局+ScrollView

主要分为PercentRelativeLayout,和 PercentFrameLayout

PercentRelativeLayout

一、添加依赖

compile 'com.android.support:percent:24.0.0'

二、XML中

<android.support.percent.PercentRelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
     <!-- 别漏了这句-->
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
...
...
...
</android.support.percent.PercentRelativeLayout>

内部的组件可以通过

  app:layout_heightPercent
  app:layout_widthPercent
  app:layout_marginTopPercent
  app:layout_marginLeftPercent
  ...
  ...

如:

app:layout_heightPercent="5%"
app:layout_widthPercent="100%"

百分比布局还可以外层嵌套一个ScrollView 实现上滑下滑 **
因为百分比布局的布局百分比不是按照百分比布局的大小来设置,而是根据屏幕的大小设置
所以百分比布局可以设置为高为 wrapContent的
但是
注意 ScrollView 只能有一个子布局**

若底部导航栏挡住了一些控件,可以在底部加一个space控件,这样就可以让ScrollView上滑,也增加了屏幕的灵活性。


三、问题

below无效

1 加一个imageView作为分隔线样式 正好也能实现below了
2 等待一下控件加载?


PercentRelativeLayout要设置为MatchParent的宽高
但是,比如一个RecyclerView的Item布局
我需要的是这个Item布局以百分比的位置设置,但是父布局又想WrapContent
该怎么办?
待填坑…


ScrollView

isNestedScrollingEnabled作用:设置控件是否支持嵌套滑动
比如垂直滑动的ScrollView嵌套recyclerView 如果设置为false 则recyclerView不可垂直滑动,横向的滑动就可以

scrollTo(position)是滚动到某个position 但是如果该position已经可见了 不会滚动的 并且就算会滚动,也只是让这个item滚动到可见 不一定在第一个位置
滚动到某个x,y具体的位置 一般要去拿某个view的x和y坐标(recyclerView.layoutManager?.getChildAt(jumpIndex)scrollBy(x,y) 让View相对于当前的位置移动一段距离
scrollTo(x,y) view的(x,y)点与手机屏幕的左上角对齐 让View相对于初始的位置移动一段距离

getX()getY()方法获取的是View左上角相对于父容器的坐标,当View没有发生平移操作时,getX()==getLeft()getY()==getTop()
scrollX表示手机屏幕显示区域左上角x坐标减去view左上角x坐标
scrollY表示手机屏幕显示区域左上角y坐标减去view左上角y坐标
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值