linkas
linkas

Reputation: 173

How to put LinearLayout at the bottom of the screen and doesn't overlap with another LinearLayout?

I have ScrollView, inside it I have RelativeLayout and inside RelativeLayout I have 2 LinearLayouts. It looks like this:

ScrollView
     RelativeLayout
          LinearLayout1
          LinearLayout2 

I want to have my LinearLayout2 at the bottom of the screen and it shouldn't overlap with LinearLayout1. When I include line android:layout_alignParentBottom="true" it shows it and the bottom, but when the TextView is longer, LinearLayout2 overlaps with LinearLayout1. When I also include line android:layout_below="@+id/linearLayout" it puts LinearLayout2 below LinearLayout1, but doesn't put it at the bottom. Here is my code:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    android:background="@drawable/background">

    <RelativeLayout
        android:layout_width="fill_parent"
        android:background="#4D000000"
        android:layout_height="fill_parent">

        <LinearLayout xmlns:tools="http://schemas.android.com/tools"
            xmlns:custom="http://schemas.android.com/apk/res-auto"
            android:layout_width="fill_parent"
            android:id="@+id/linearLayout"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingTop="?attr/actionBarSize"
            android:padding="5dp"
            tools:context="com.daimajia.slider.demo.MainActivity">

            <com.daimajia.slider.library.SliderLayout
                android:id="@+id/slider"
                android:layout_width="match_parent"
                custom:pager_animation="Default"
                custom:indicator_visibility="visible"
                custom:pager_animation_span="1100"
                android:layout_height="200dp" />

            <com.daimajia.slider.library.Indicators.PagerIndicator
                android:id="@+id/custom_indicator"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                custom:selected_color="#0095BF"
                custom:unselected_color="#55333333"
                custom:shape="oval"
                custom:selected_padding_left="5dp"
                custom:selected_padding_right="5dp"
                custom:unselected_padding_left="5dp"
                custom:unselected_padding_right="5dp"
                custom:selected_width="6dp"
                custom:selected_height="6dp"
                custom:unselected_width="6dp"
                custom:unselected_height="6dp" />

            <com.daimajia.slider.library.Indicators.PagerIndicator
                android:id="@+id/custom_indicator2"
                style="@style/AndroidImageSlider_Corner_Oval_Orange"
                android:layout_marginBottom="10dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

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

                <TextView
                    android:id="@+id/address"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Konstitucijos pr. 7A, Vilnius"
                    android:textColor="#FFFFFF" />

                <ImageButton
                    android:id="@+id/pin"
                    android:layout_width="32dp"
                    android:layout_height="32dp"
                    android:layout_alignParentRight="true"
                    android:layout_marginRight="5dp"
                    android:background="@drawable/pin" />
            </RelativeLayout>

            <View
                android:id="@+id/divider1"
                android:layout_width="fill_parent"
                android:layout_height="1dp"
                android:background="#433b39"
                android:layout_marginTop="10dp" />

            <TextView
                android:id="@+id/work_hours"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="I - VI 10:00 - 21:00, VII 10:00 - 20:00"
                android:textColor="#FFFFFF"
                android:layout_marginTop="10dp" />

            <View
                android:id="@+id/divider2"
                android:layout_width="fill_parent"
                android:layout_height="1dp"
                android:background="#433b39"
                android:layout_marginTop="10dp" />

            <TextView
                android:id="@+id/description"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:textColor="#FFFFFF" />

            <FrameLayout
                android:id="@+id/frame_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <fragment
                    android:name="com.google.android.youtube.player.YouTubePlayerSupportFragment"
                    android:id="@+id/youtube_fragment"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
            </FrameLayout>

            <View
                android:id="@+id/divider3"
                android:layout_width="fill_parent"
                android:layout_height="1dp"
                android:background="#575350"
                android:layout_marginTop="10dp" />

            <RelativeLayout
                android:layout_width="fill_parent"
                android:id="@+id/rl"
                android:layout_height="wrap_content">

                <RatingBar
                    android:id="@+id/ratingBar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:numStars="5"
                    android:stepSize="1.0"
                    android:rating="0" />

                <TextView
                    android:layout_width="fill_parent"
                    android:id="@+id/rating_text"
                    android:layout_below="@+id/ratingBar"
                    android:layout_height="wrap_content"
                    android:gravity="center" />

            </RelativeLayout>

            <View
                android:id="@+id/divider4"
                android:layout_width="fill_parent"
                android:layout_height="1dp"
                android:background="#575350" />
        </LinearLayout>

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:layout_alignParentBottom="true"
            android:layout_below="@+id/linearLayout"
            android:orientation="horizontal"
            android:weightSum="1.0">

            <ImageView
                android:id="@+id/number"
                android:layout_height="wrap_content"
                android:layout_weight=".5"
                android:layout_width="0dip"
                android:src="@drawable/telefonas" />

            <ImageView
                android:id="@+id/email"
                android:layout_height="wrap_content"
                android:layout_weight=".5"
                android:layout_width="0dip"
                android:src="@drawable/laiskas" />
        </LinearLayout>
    </RelativeLayout>
</ScrollView>

What am I doing wrong?

Upvotes: 0

Views: 359

Answers (3)

linkas
linkas

Reputation: 173

I solved this with @PedroHawk help. I just needed to change the hierarchy of those layouts to this:

ScrollView
     LinearLayout1
          RelativeLayout
              LinearLayout2 

Upvotes: 0

Sarthak Mittal
Sarthak Mittal

Reputation: 6104

You presently are assigning android:layout_below to the bottom layout, remove that and assign android:layout_above to the layout above.

Since you are inside a ScrollView it would be better to do this:

Keep the android:layout_below as it is, but remove the android:layout_alignParentBottom="true"

Upvotes: 1

Francesco D.M.
Francesco D.M.

Reputation: 2227

I noticed two things. The first one is that you use fill_parent istead of match_parent . If I am not mistaken the two are equivalent but the first is deprecated.
The second one is that you didn't specify android:layout_alignParentTop in the first LinearLayout. Try to change these two things and see if they solve your problem

Upvotes: 0

Related Questions