Home > Back-end >  Set element height till end of view
Set element height till end of view

Time:11-11

Guys I have the code above which looks like this:

example

The issue is that I need to set the height hardcoded in order to make it visible. What I want is to set the height till the bottom of my mainview.

Is this possible using the height attribute or do I need to use other attributes? My current implementation looks like this:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".pkgFragment.LocationAddFragment">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:id="@ id/llLayoutAddLocation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@ id/abLayoutAddLocation"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
            android:orientation="vertical">

            <GridLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:columnCount="2"
                android:rowCount="1"
                >
            
                <com.google.android.material.switchmaterial.SwitchMaterial
                    android:layout_columnWeight="1"
                    android:layout_height="match_parent"
                    android:text="@string/vehicle_name"/>
                <com.google.android.material.switchmaterial.SwitchMaterial
                    android:layout_columnWeight="1"
                    android:layout_height="match_parent"
                    android:text="@string/vehicle_name"/>
            </GridLayout>

        </LinearLayout>

        <org.osmdroid.views.MapView
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_below="@id/llLayoutAddLocation"

            >

        </org.osmdroid.views.MapView>
    </RelativeLayout>
</ScrollView>

CodePudding user response:

I MapView's height/width doesn't need to be hardcoded. I checked the repo myself. You can use match_parent to fill up the whole bottom area. Here is the sample from the repo MapView Sample Layout .

I suggest, Instead of RelativeLayout, use LinearLayout as the child(only) of ScrollView and set the MapView Height to match_parent.

Your code will look like this:

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:id="@ id/llLayoutAddLocation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
            android:orientation="vertical">

            <GridLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:columnCount="2"
                android:rowCount="1"
                >
            
                <com.google.android.material.switchmaterial.SwitchMaterial
                    android:layout_columnWeight="1"
                    android:layout_height="match_parent"
                    android:text="@string/vehicle_name"/>
                <com.google.android.material.switchmaterial.SwitchMaterial
                    android:layout_columnWeight="1"
                    android:layout_height="match_parent"
                    android:text="@string/vehicle_name"/>
            </GridLayout>

        </LinearLayout>

        <org.osmdroid.views.MapView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >

        </org.osmdroid.views.MapView>
    </LinearLayout>

Edit: I've edited the answer. Remove the scrollview and set the height and width of the Parent LinearLayout to match_parent.

  • Related