添加依赖
implementation ‘com.android.support:percent:25.2.0’
我的项目是AndroidX的,依然用这个依赖哦~
代码使用
<androidx.percentlayout.widget.PercentFrameLayout 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"
tools:context=".activitys.PercentActivity">
<Button
app:layout_widthPercent="50%"
app:layout_heightPercent="50%"
/>
<Button
android:layout_gravity="right"
app:layout_widthPercent="50%"
app:layout_heightPercent="50%"
/>
<Button
android:color="#16F145"
android:layout_gravity="bottom"
app:layout_widthPercent="50%"
app:layout_heightPercent="50%"
/>
<Button
android:color="#F44336"
android:layout_gravity="right|bottom"
app:layout_widthPercent="50%"
app:layout_heightPercent="50%"
/>
</androidx.percentlayout.widget.PercentFrameLayout>
- app:layout_widthPercent = " %" 设置宽度百分比
- app:layout_heightPercent = " %" 设置高度百分比
效果图(1.1)
:
原创不易,您的点赞就是对我最大的支持o~