0

I want to achieve a layout below. enter image description here

ISSUE: Irrespective to screen size all view groups in this layout should be visible in single screen without scroll.

What I have done: I have used Gridview for bottom tabs layout.And above Image layout height is dynamic as I have to maintain 16:9 ratio.

What i am getting : enter image description here

My bottom layout which is grid view is scrolling. My grid view items are square.

Code:

GridViewItem

<com.app.phlebo.customViews.MyLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/ll_profile"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_gravity="bottom"
    android:background="@drawable/curved_edge"
    android:gravity="center"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/img_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

    <com.app.phlebo.customViews.TextViewPlus
        android:id="@+id/tv_title"
        android:layout_width="wrap_content"
        android:layout_height="37dp"
        android:layout_below="@+id/img_icon"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:textColor="@android:color/black"
        android:textSize="@dimen/text_size"
        app:fonts="Montserrat-Light.otf" />
</com.app.phlebo.customViews.MyLinearLayout>

My Custom Linear Layout (Used in Grid view Items )

public class MyLinearLayout extends LinearLayout

    {
    public MyLinearLayout(Context context) {
        super(context);
    }

    public MyLinearLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        final int width = getDefaultSize(getSuggestedMinimumWidth(),widthMeasureSpec);
        setMeasuredDimension(width, width);
    }
}

My content_main.xml

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:showIn="@layout/activity_main"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="5dp"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/curve_edge_transparent"
            android:id="@+id/rl">

            <include layout="@layout/layout_welcome"
                android:id="@+id/layout_dots"/>

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="5dp">

            <RelativeLayout
                android:id="@+id/sp_date"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="3dp"
                android:background="@drawable/cornor_layout">


                <com.app.phlebo.customViews.TextViewPlus
                    android:layout_width="match_parent"
                    android:layout_height="35dp"
                    android:textSize="@dimen/text_size"
                    android:gravity="center_vertical"
                    android:textColor="@color/black"
                    android:id="@+id/spinner"
                    android:padding="5dp"
                    android:text="Today"
                    app:fonts="Montserrat-Medium.otf" />

                <ImageView
                    android:layout_width="30dp"
                    android:layout_height="35dp"
                    android:id="@+id/img_dots"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentEnd="true"
                    android:gravity="center_vertical"
                    android:paddingRight="5dp"
                    android:src="@drawable/more_line" />

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_below="@+id/spinner"
                    android:layout_marginLeft="15dp"
                    android:layout_marginRight="15dp"
                    android:layout_marginTop="5dp"
                    android:id="@+id/view_middle"
                    android:background="#E5E5E5"/>

                <RelativeLayout
                    android:id="@+id/rl_middle"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/view_middle">

                    <View
                        android:id="@+id/center_shim"
                        android:layout_width="2dp"
                        android:layout_height="20dp"
                        android:layout_centerInParent="true"
                        android:layout_marginBottom="10dp"
                        android:layout_marginTop="10dp"
                        android:background="#E5E5E5" />

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/ll_accepted_request"
                        android:layout_centerInParent="true"
                        android:layout_toLeftOf="@+id/center_shim"
                        android:gravity="center"
                        android:orientation="vertical"
                        android:padding="2dp">

                        <com.app.phlebo.customViews.TextViewPlus
                            android:id="@+id/tv_count_accepted_request"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_toLeftOf="@+id/center_shim"
                            android:gravity="center"
                            android:text=""
                            android:textColor="@color/colorPrimary"
                            android:textSize="25sp"
                            app:fonts="Montserrat-SemiBold.otf" />


                        <com.app.phlebo.customViews.TextViewPlus
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:text="Accepted Request"
                            android:textColor="@android:color/black"
                            android:textSize="@dimen/text_size"
                            app:fonts="Montserrat-Light.otf"/>
                    </LinearLayout>


                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true"
                        android:id="@+id/ll_pending_request"
                        android:layout_toRightOf="@+id/center_shim"
                        android:gravity="center"
                        android:orientation="vertical"
                        android:padding="2dp">

                        <com.app.phlebo.customViews.TextViewPlus
                            android:id="@+id/tv_count_rejected_request"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:text=""
                            android:textColor="@color/dashboard_red"
                            android:textSize="25sp"
                            app:fonts="Montserrat-SemiBold.otf"/>

                        <com.app.phlebo.customViews.TextViewPlus
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:text="Pending Request"
                            app:fonts="Montserrat-Light.otf"
                            android:textColor="@android:color/black"
                            android:textSize="@dimen/text_size" />

                    </LinearLayout>
                </RelativeLayout>

            </RelativeLayout>



            <GridView
                android:id="@+id/gridview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/sp_date"
                android:layout_alignParentBottom="true"
                android:layout_marginTop="3dp"
                android:numColumns="3"
                android:gravity="center"
                android:horizontalSpacing="5dp"
                android:verticalSpacing="5dp"
                />

        </RelativeLayout>
    </LinearLayout>

Please help me to achieve the above layout. I want all in single screen without scroll.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
young_08
  • 1,196
  • 2
  • 13
  • 35

1 Answers1

0

The solution is quite simple. You have used "com.app.phlebo.customViews.MyLinearLayout" as parent layout.BUT it extends Linear Layout. Linear Layout is scrollable by default.

So, to avoid grid components going below screen (to contain within a screen) Change height of Image View to a specific height.(height remaining after adding grid components) Note : I assume that the grid components are in fixed numbers.Other

<ImageView
    android:id="@+id/img_icon"
    android:layout_width="wrap_content"
    android:layout_height="200dp"  // Find height needed and set
    android:layout_centerInParent="true" />
  • My grid row item has image view and Textview. It has to be in some container. – young_08 Dec 02 '17 at 20:29
  • Yeah i got your point, but what i meant is that as it is in a Linear Layout (which is scrollable by default) your other textview change position according to the height of the image on the top.(It was the reason for your problem)..No need to alter the linear layout , just fix a suitable height for the imageView. hope it helps :-) –  Dec 03 '17 at 04:11