我想在80%的屏幕和一個按鈕中分割一個GridView,並在剩下的20%中分配一個adView。這是我的XML。在Android中佈置多個元素的最佳做法是什麼?在LinearLayout中劃分佈局的問題
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:orientation="vertical"
android:weightSum="10"
tools:context="com.apptree.snapper.dashboard.DashboardActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weight="8"
android:orientation="vertical">
<GridView
android:id="@+id/dashboard_grid_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"></GridView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weight="2"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:id="@+id/dashboard_takeSnapButton"
android:text="@string/singin_take_snap_button"
android:layout_height="50dp"
/>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/dashboard_adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-1390609726414683/7854545655"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true">
</com.google.android.gms.ads.AdView>
</LinearLayout>
</LinearLayout>
但它沒有給我那個結果。我錯過了什麼?
這是輸出。
使用PercentRelativeLayout –