Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android margin top negative value in ScrollView

I had tried to give negative marginTop value to the child inside scrollview. But it was not aligning as expected. It was hiding below layout which is above the scrollview. I want to achieve the design which i mentioned in Screenshot. Particularly the logo which was floating 75% in banner and 25% below banner. Could anyone give your ideas for that.

I was using android support design library latest.

enter image description here

like image 655
Chris Avatar asked Sep 09 '25 10:09

Chris


1 Answers

I have just implemented same layout design. I would like to share it with you. Hope it will help you.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF">

    <LinearLayout
        android:id="@+id/layoutActionbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/actionbar_background"
        android:orientation="horizontal">


        <TextView
            android:id="@+id/txtBack"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="@mipmap/back" />

        <TextView
            android:id="@+id/lblHeader"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left|center"
            android:layout_margin="5dp"
            android:text=""
            android:textColor="#FFFFFF"
            android:textSize="18sp"
            android:textStyle="bold" />

    </LinearLayout>

    <RelativeLayout
        android:id="@+id/layoutTop"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_below="@+id/layoutActionbar"
        android:background="#F0F0F0"
        android:gravity="center">

        <TextView
            android:id="@+id/txtTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/txtSubTitle"
            android:layout_centerHorizontal="true"
            android:gravity="center"
            android:lines="2"
            android:paddingLeft="50dp"
            android:paddingRight="50dp"
            android:text=""
            android:textSize="20sp" />

        <TextView
            android:id="@+id/txtSubTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:lines="2"
            android:paddingLeft="50dp"
            android:paddingRight="50dp"
            android:text=""
            android:textSize="20sp" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/layoutBottom"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_alignParentBottom="true"
        android:layout_below="@id/layoutTop">


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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">


                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginLeft="22dp"
                    android:layout_marginStart="22dp"
                    android:layout_marginTop="40dp"
                    android:text="ADDITIONAL INFORMATION"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#007DCE" />


                <TextView
                    android:id="@+id/txtDescreiption"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="22dp"
                    android:layout_marginRight="15dp"
                    android:layout_marginTop="15dp"
                    android:text=""
                    android:textAppearance="?android:attr/textAppearanceSmall" />


                <TextView
                    android:id="@+id/textView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginLeft="22dp"
                    android:layout_marginStart="22dp"
                    android:layout_marginTop="20dp"
                    android:text="SOURCES and LINKS"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#007DCE" />

                <TextView
                    android:id="@+id/txtWebsites"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="22dp"
                    android:layout_marginRight="15dp"
                    android:layout_marginTop="10dp"
                    android:layout_marginBottom="10dp"
                    android:autoLink="web"
                    android:text=""
                    android:textAppearance="?android:attr/textAppearanceSmall" />

            </LinearLayout>
        </ScrollView>
    </RelativeLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_above="@id/layoutBottom"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="-20dp"
        android:adjustViewBounds="true"
        android:background="#F0F0F0">

        <ImageView
            android:id="@+id/favImage"
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:src="@mipmap/ic_favourite_selected" />
    </LinearLayout>


</RelativeLayout>
like image 162
Mit Bhatt Avatar answered Sep 11 '25 08:09

Mit Bhatt