依存関係を追加する
実装 '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)
:
オリジナリティは簡単ではありません、あなたの好きなものはあなたの最大のサポートです〜