Я действительно изо всех сил пытаюсь понять, как заставить линейные макеты принимать правильные пропорции в рамках моей xml активности.
Ниже приведен мой код. По сути, есть 3 слоя (помечены первый слой, второй слой и третий слой). Я хочу, чтобы они были выровнены по вертикали, чтобы этот слой 1 занимал около 10% верхнего экрана, позже 2 занимал следующие 10% экрана, а затем слой 3 занимал оставшиеся 80% экрана.
С помощью приведенного ниже кода виджеты в верхних 2 слоях расправляются, и поэтому я не вижу полных виджетов. Я уверен, что это связано с тем, как я использую веса макетов, но я просто не уверен, как это исправить.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="@+id/layTopLevel"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/colorPrimaryDark"
android:weightSum="10"
android:orientation="vertical">
<!--layer one-->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/layerOne"
android:gravity="center_vertical"
android:layout_weight="1">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/customborder"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_weight="0.5"
>
<LinearLayout
android:id="@+id/layoutName"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="@drawable/customborder"
android:orientation="vertical">
<TextView
android:id="@+id/txtMyPlaceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/myPlaceName" />
<EditText
android:id="@+id/etMyPlaceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter name here"
android:singleLine="true" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_weight="0.5"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/layoutType"
android:layout_weight="1"
android:background="@drawable/customborder"
android:orientation="vertical" >
<TextView
android:id="@+id/txtMyPlaceType"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="@string/myPlaceType" />
<Spinner
android:id="@+id/spnType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style = "@style/Widget.AppCompat.Spinner.Underlined"
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
<!--Layer Two-->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/layerTwo"
android:gravity="center_vertical"
android:layout_weight="1">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="@drawable/customborder"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_weight="0.333">
<Button
android:id="@+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:onClick="addSightingToDb"
android:text="@string/addSighting" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_weight="0.333">
<Button
android:id="@+id/btnClearLast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:onClick="addSightingToDb"
android:text="@string/addSighting" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_weight="0.334">
<Button
android:id="@+id/btnClearAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:onClick="addSightingToDb"
android:text="@string/addSighting" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
<!--Layer three-->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/layerThree"
android:gravity="center_vertical"
android:layout_weight="8">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</RelativeLayout>
</LinearLayout>
<!--<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="fill_parent"-->
<!--xmlns:app="http://schemas.android.com/apk/res-auto"-->
<!--android:layout_marginTop="10dp"-->
<!--android:background="@color/colorPrimaryDark"-->
<!--android:orientation="horizontal">-->
<!--<LinearLayout-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="fill_parent"-->
<!--android:orientation="vertical">-->
<!--<LinearLayout-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="fill_parent"-->
<!--android:layout_weight="1"-->
<!--android:background="@drawable/customborder"-->
<!--android:orientation="vertical" >-->
<!--<!–first row–>-->
<!--<LinearLayout-->
<!--android:layout_width="fill_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_weight="0.5"-->
<!--android:background="@drawable/customborder"-->
<!--android:layout_marginBottom="5dp"-->
<!--android:orientation="horizontal" >-->
<!--<RelativeLayout-->
<!--android:layout_width="fill_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:gravity="center_vertical"-->
<!--android:layout_weight="0.50">-->
<!--<LinearLayout-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_weight="1"-->
<!--android:background="@drawable/customborder"-->
<!--android:orientation="vertical" >-->
<!--<TextView-->
<!--android:id="@+id/txtMyPlaceName"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:text="@string/myPlaceName" />-->
<!--<EditText-->
<!--android:id="@+id/etMyPlaceName"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:singleLine="true" />-->
<!--</LinearLayout>-->
<!--</RelativeLayout>-->
<!--<RelativeLayout-->
<!--android:layout_width="fill_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:gravity="center_vertical"-->
<!--android:layout_weight="0.50">-->
<!--<LinearLayout-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_weight="1"-->
<!--android:background="@drawable/customborder"-->
<!--android:orientation="vertical" >-->
<!--<TextView-->
<!--android:id="@+id/txtMyPlaceType"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:text="@string/myPlaceType" />-->
<!--<Spinner-->
<!--android:id="@+id/spnSeenHeard"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--style = "@style/Widget.AppCompat.Spinner.Underlined"-->
<!--/>-->
<!--</LinearLayout>-->
<!--</RelativeLayout>-->
<!--</LinearLayout>-->
<!--<!–button row–>-->
<!--<LinearLayout-->
<!--android:layout_width="fill_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_weight="0.50"-->
<!--android:background="@drawable/customborder"-->
<!--android:layout_marginBottom="10dp"-->
<!--android:orientation="horizontal" >-->
<!--<RelativeLayout-->
<!--android:layout_width="fill_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:gravity="center_vertical"-->
<!--android:layout_weight="0.34">-->
<!--<Button-->
<!--android:id="@+id/btnAdd"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:gravity="left|center_vertical"-->
<!--android:onClick="addSightingToDb"-->
<!--android:text="@string/addSighting" />-->
<!--</RelativeLayout>-->
<!--<RelativeLayout-->
<!--android:layout_width="fill_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:gravity="center_vertical"-->
<!--android:layout_weight="0.33">-->
<!--<Button-->
<!--android:id="@+id/btnClearLast"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:gravity="left|center_vertical"-->
<!--android:onClick="addSightingToDb"-->
<!--android:text="@string/addSighting" />-->
<!--</RelativeLayout>-->
<!--<RelativeLayout-->
<!--android:layout_width="fill_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:gravity="center_vertical"-->
<!--android:layout_weight="0.33">-->
<!--<Button-->
<!--android:id="@+id/btnClearAll"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:gravity="left|center_vertical"-->
<!--android:onClick="addSightingToDb"-->
<!--android:text="@string/addSighting" />-->
<!--</RelativeLayout>-->
<!--</LinearLayout>-->
<!--<!–Map row–>-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_map"-->
<!--android:layout_width="fill_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_weight="0.50"-->
<!--android:background="@drawable/customborder"-->
<!--android:layout_marginBottom="5dp"-->
<!--android:orientation="horizontal" >-->
<!--<RelativeLayout-->
<!--android:id="@+id/map_layout"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent">-->
<!--<fragment-->
<!--android:id="@+id/map"-->
<!--android:name="com.google.android.gms.maps.SupportMapFragment"-->
<!--android:layout_width="fill_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_alignParentStart="true"-->
<!--android:layout_alignParentTop="true" />-->
<!--</RelativeLayout>-->
<!--</LinearLayout>-->
<!--</LinearLayout>-->
<!--</LinearLayout>-->
<!--</LinearLayout>-->