android view layout. make view fill space between views - java

I am trying to create a layout with basically a head, body, and footer. The ViewPager I am using is filling the space behind the footer content though. How can I make it not do this, and cutoff at the start of the footer content?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.janedoe.anothertabexample.MainActivity"
tools:showIn="#layout/activity_main">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="#id/tabLayout"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp">
<TextView
android:id="#+id/time"
android:layout_width="100dp"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="00:00:00"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/mileage"
android:layout_width="100dp"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:gravity="center"
android:text="0.0 mi"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:layout_width="80dp"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#id/time"
android:text="Start" />
<Button
android:layout_width="80dp"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#id/mileage"
android:text="Stop" />
</RelativeLayout>
</RelativeLayout>
I don't want the color(which is just the content) to run past the Buttons and TextViews on the bottom. I've tried the layout_gravity method as well as setting the viewpager to layout_above and layout_blow but neither appear to work. How can I achieve this?

You view pager will consume all space available.
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="#id/tabLayout"/>
I would try switching to a LinearLayout and use the "android:layout_weight" property to force the ViewPager to only use available space.

your RelativeLayout should have android:layout_alignParentBottom="true".
<RelativeLayout android:id="#+id/relativeFooter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingBottom="5dp">
Remove android:layout_alignParentBottom="true" from all its child.
and your viewpager should look like below
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/relativeFooter"
android:layout_below="#id/tabLayout"/>
Finally your whole layout should be like below :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/relativeFooter"
android:layout_below="#id/tabLayout"/>
<RelativeLayout android:id="#+id/relativeFooter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingBottom="5dp">
<TextView
android:id="#+id/time"
android:layout_width="100dp"
android:layout_height="55dp"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="00:00:00"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/mileage"
android:layout_width="100dp"
android:layout_height="55dp"
android:layout_alignParentRight="true"
android:gravity="center"
android:text="0.0 mi"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:layout_width="80dp"
android:layout_height="55dp"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#id/time"
android:text="Start" />
<Button
android:layout_width="80dp"
android:layout_height="55dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#id/mileage"
android:text="Stop" />
</RelativeLayout>

Related

ViewPager under of BottomNavigation

I have list in viewpager and i have audio player on bottom. But my viewpager doesn't end the starting of audio player. I can't see my last 2 - 3 items in viewpager. And i don't wanna use MarginBottom.
some screenshots
my activity.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/coordinatorLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- AppBar Layout -->
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="fill_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<!-- Tab Layout for creating tabs -->
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<!-- Helps handing the Fragments for each Tab -->
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="fill_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.BottomNavigationView
android:layout_width="fill_parent"
android:layout_height="90dp"
android:layout_marginTop="5dp"
android:layout_below="#+id/viewPager"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_gravity="bottom"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<android.support.design.widget.NavigationView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:paddingLeft="10dp"
android:layout_gravity="center"
android:paddingRight="10dp"
android:orientation="horizontal">
<ImageButton
android:id="#+id/btnBackward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="50dp"
android:layout_marginBottom="4dp"
android:src="#android:drawable/ic_media_rew" />
<ImageButton
android:id="#+id/btnPlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/btnBackward"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/btnBackward"
android:src="#android:drawable/ic_media_play" />
<ImageButton
android:id="#+id/btnPause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/btnPlay"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/btnPlay"
android:src="#android:drawable/ic_media_pause" />
<ImageButton
android:id="#+id/btnForward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/btnPause"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/btnPause"
android:contentDescription="#+id/imageButton3"
android:src="#android:drawable/ic_media_ff" />
<TextView
android:id="#+id/txtStartTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/sBar"
android:text="0 min, 0 sec" />
<SeekBar
android:id="#+id/sBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/btnBackward"
android:layout_toLeftOf="#+id/txtSongTime"
android:layout_toRightOf="#+id/txtStartTime" />
<TextView
android:id="#+id/txtSongTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/sBar"
android:layout_toRightOf="#+id/btnForward"
android:text="0 min, 0 sec " />
</RelativeLayout>
</android.support.design.widget.NavigationView>
</android.support.design.widget.BottomNavigationView>
</android.support.design.widget.CoordinatorLayout>
I tried a couple solution but none of them worked. Only solution i can find is using marginbottom, but i think that would be bad choices.
Any help would be great. Thanks.
You can solve this by wrapping the ViewPager and the BottomNavigationView within a ConstraintLayout and add a constraint so that the bottom part of the ViewPager should be at the top part of the BottomNavigationView using: app:layout_constraintBottom_toTopOf attribute at the ViewPager
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
...
app:layout_constraintBottom_toTopOf="#id/bottom_nav_view"
And then make the height of the ViewPager match the constraints instead of the fill_parent or match_parent
To apply this change your layout to:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/coordinatorLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- AppBar Layout -->
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="fill_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<!-- Tab Layout for creating tabs -->
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<!-- Helps handing the Fragments for each Tab -->
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
app:layout_constraintBottom_toTopOf="#id/bottom_nav_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_nav_view"
android:layout_width="match_parent"
android:layout_height="90dp"
android:layout_marginTop="5dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_constraintBottom_toBottomOf="parent"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<android.support.design.widget.NavigationView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<ImageButton
android:id="#+id/btnBackward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="50dp"
android:layout_marginBottom="4dp"
android:src="#android:drawable/ic_media_rew" />
<ImageButton
android:id="#+id/btnPlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/btnBackward"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/btnBackward"
android:src="#android:drawable/ic_media_play" />
<ImageButton
android:id="#+id/btnPause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/btnPlay"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/btnPlay"
android:src="#android:drawable/ic_media_pause" />
<ImageButton
android:id="#+id/btnForward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/btnPause"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/btnPause"
android:contentDescription="#+id/imageButton3"
android:src="#android:drawable/ic_media_ff" />
<TextView
android:id="#+id/txtStartTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/sBar"
android:text="0 min, 0 sec" />
<SeekBar
android:id="#+id/sBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/btnBackward"
android:layout_toLeftOf="#+id/txtSongTime"
android:layout_toRightOf="#+id/txtStartTime" />
<TextView
android:id="#+id/txtSongTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/sBar"
android:layout_toRightOf="#+id/btnForward"
android:text="0 min, 0 sec " />
</RelativeLayout>
</android.support.design.widget.NavigationView>
</android.support.design.widget.BottomNavigationView>
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.CoordinatorLayout>
Edit:
It's kind of worked. Bottom is fixed bot now i can't see Top, first 2 3 item under appBar. i tried couple of codes something like that app:layout_constraintBottom_toBottomOf="#id/appBarLayout" but doesn't worked.
Solution:
app:layout_constraintTop_toBottomOf="#+id/appBarLayout" and to gradle 'com.android.support.constraint:constraint-layout:1.0.2' now it's working.

Android: How to get the Calendar in YEAR/MONTH/DATE Spinners

In my Android app, I am trying to get the birthday of the user. Below is my XML document .
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/colorPurple"
app:popupTheme="#style/AppTheme.PopupOverlay"
style="#style/MyDrawerArrowToggle"
android:layout_marginTop="#dimen/toolbar_layout_top_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="30dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:id="#+id/signUp_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/back_arrow_white" />
</LinearLayout>
<LinearLayout
android:layout_width="220dp"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="20dp"
android:text="#string/birthday"
android:textColor="#color/colorWhite"
android:gravity="center|left"
android:paddingLeft="20dp"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18dp"
android:textStyle="bold"
android:text="#string/what_is_your_birthday"
android:gravity="center"
android:layout_marginTop="60dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="30dp">
<DatePicker
android:layout_width="match_parent"
android:layout_height="150dp"
android:datePickerMode="spinner"
android:id="#+id/date_picker"/>
<!--<com.aigestudio.wheelpicker.widgets.WheelDayPicker-->
<!--android:layout_width="50dp"-->
<!--android:layout_height="match_parent" />-->
<!--<com.aigestudio.wheelpicker.widgets.WheelMonthPicker-->
<!--android:layout_width="50dp"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_marginLeft="20dp"/>-->
<!--<com.aigestudio.wheelpicker.widgets.WheelYearPicker-->
<!--android:layout_width="50dp"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_marginLeft="20dp"/>-->
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#color/colorPurple"
android:layout_marginTop="40dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:id="#+id/signup_birthday_next_button_layout">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text = "#string/next_text"
android:textColor="#color/colorWhite"
android:textSize="14dp"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
This gives me the below UI
But I am looking for the below
How can I get the second UI?
Please add this xml file it may be help full to solve your problem.
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:gravity="center"
android:id="#+id/btnNotification"
android:text="What is your birthday"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<DatePicker
android:id="#+id/spinnerDatePicker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:calendarViewShown="false"
android:datePickerMode="spinner"
android:descendantFocusability="blocksDescendants"
android:focusable="true"
android:spinnersShown="true" />
<Button
android:text="next"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
You can use SpinnerDatePicker open source library it has UI like below
As it is open source you can change if you need.

scrollview not scrolling android

The ScrollView item is not doing what it should: I canĀ“t scroll.
The code below is a part from a fragment, with splitted screen (thats why I use weight=1). The content of the RelativeLayout is added via code dynamically. The content appears correctly, it is more that could fit onto the screen, so it should be possible to scroll.
I tried out several things:
changing RelativesLayout-height to wrap-content
adding fillViewport="true" to the ScrollView
scrollview not as root element
THE LAYOUT FILE OF THE FRAGMENT
<LinearLayout
android:id="#+id/schichten"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="tuerk.fabian.polarfuchs.AllgemeineInfosFragment">
<ScrollView
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:fillViewport="true" >
<RelativeLayout android:id="#+id/schichten_upper_half"
android:isScrollContainer="true"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"/>
</ScrollView>
THE LAYOUT FILE OF THE CONTENT THAT IS DYNAMICALLY ADDED TO THE FRAGMENT (INTO #+id/schichten_upper_half)
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true">
<TextView
android:id="#+id/schichten_ansicht_haerte"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FA"
android:textSize="20sp"
android:paddingRight="10sp"
android:layout_centerVertical="true"/>
<TextView
android:id="#+id/schichten_ansicht_von_height"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10 cm"
android:layout_toRightOf="#+id/schichten_ansicht_haerte"/>
<TextView
android:id="#+id/schichten_ansicht_bis_height"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10 cm"
android:layout_below="#id/schichten_ansicht_von_height"
android:layout_toRightOf="#+id/schichten_ansicht_haerte"/>
<TextView
android:id="#+id/schichten_ansicht_naesse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:textSize="20sp"
android:paddingLeft="10sp"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/schichten_ansicht_bis_height"/>
<ImageView
android:id="#+id/schichten_ansicht_1st_grain_form"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/df"
android:paddingLeft="10sp"
android:layout_toRightOf="#id/schichten_ansicht_naesse"/>
<ImageView
android:id="#+id/schichten_ansicht_2nd_grain_form"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/df"
android:layout_toRightOf="#id/schichten_ansicht_1st_grain_form"/>
<TextView
android:id="#+id/schichten_ansicht_durchmesser_von"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0.1 "
android:layout_centerVertical="true"
android:paddingLeft="10sp"
android:layout_toRightOf="#+id/schichten_ansicht_2nd_grain_form"/>
<TextView
android:id="#+id/schichten_ansicht_durchmesser_bis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="- 0.3 mm"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/schichten_ansicht_durchmesser_von"/>
</RelativeLayout>
THE LAYOUT FILE OF THE ACITIVITY
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/appbar_padding_top"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#android:drawable/ic_dialog_email" />

java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout : XML

I am facing issue in android xml. I get error like above but as per my I have not given Circular dependencies in my xml. I am trying from last 1 hour for fix it but I am not able to complete it. I have used above and below as per requirement. I am attaching my xml here. Let me know if someone can point me where I am wrong. My XML is like below
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
xmlns:fab="http://schemas.android.com/apk/res-auto"
tools:context="com.karopass.karoshare.ImageDetails">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_imageDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:theme="#style/AppTheme.AppBarOverlay"
app:popupTheme="#style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<com.example.utils.ExtendedViewPager
android:id="#+id/view_pager_extended"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/pageNavCount"
android:layout_below="#+id/toolbar_imageDetails"
android:background="#color/image_back"/>
<LinearLayout
android:background="#color/colorPrimary"
android:id="#+id/pageNavCount"
android:orientation="horizontal"
android:layout_above="#+id/devider"
android:layout_width="match_parent"
android:layout_height="20dp">
<RelativeLayout
android:layout_weight="3"
android:id="#+id/new_time_count"
style="#style/SelectableItemBackground"
android:layout_width="0dp"
android:layout_height="match_parent">
<TextView
android:id="#+id/txt_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1 Month ago"
android:textSize="12sp"
android:paddingLeft="5sp"
android:layout_centerVertical="true"
android:textColor="#cccccc"
android:gravity="center|start" />
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:id="#+id/new_share_count"
style="#style/SelectableItemBackground"
android:layout_width="0dp"
android:layout_height="match_parent">
<TextView
android:id="#+id/share_count"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="999"
android:textSize="12sp"
android:paddingLeft="5sp"
android:layout_centerVertical="true"
android:textColor="#cccccc"
android:gravity="center|start" />
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
style="#style/SelectableItemBackground"
android:id="#+id/new_save_count"
android:layout_width="0dp"
android:layout_height="match_parent">
<TextView
android:id="#+id/like_count"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="999"
android:textSize="12sp"
android:paddingLeft="5sp"
android:layout_centerVertical="true"
android:textColor="#cccccc"
android:gravity="center|start" />
</RelativeLayout>
</LinearLayout>
<View
android:id="#+id/devider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="#+id/pageNavLayout"
android:background="#ffffff" />
<LinearLayout
android:background="#color/colorPrimary"
android:id="#+id/pageNavLayout"
android:orientation="horizontal"
android:layout_above="#+id/ll_adLayout_latest"
android:layout_width="match_parent"
android:layout_height="48dp">
<RelativeLayout
android:layout_weight="1"
android:id="#+id/new_time"
style="#style/SelectableItemBackground"
android:clickable="true"
android:layout_width="0dp"
android:layout_height="match_parent">
<ImageView
android:layout_centerInParent="true"
android:scaleType="fitCenter"
android:src="#mipmap/ic_past_961"
android:layout_width="#dimen/nav_but_size"
android:layout_height="#dimen/nav_but_size" />
</RelativeLayout>-->
<TextView
android:background="#ffffff"
android:layout_width="1dp"
android:layout_height="match_parent" />
<RelativeLayout
android:id="#+id/new_copy"
android:clickable="true"
style="#style/SelectableItemBackground"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent">
<ImageView
android:layout_centerInParent="true"
android:src="#mipmap/ic_copy_96"
android:layout_width="#dimen/nav_but_size"
android:layout_height="#dimen/nav_but_size" />
</RelativeLayout>
<TextView
android:background="#ffffff"
android:layout_width="1dp"
android:layout_height="match_parent" />
<RelativeLayout
android:layout_weight="1"
android:id="#+id/new_save"
style="#style/SelectableItemBackground"
android:clickable="true"
android:layout_width="0dp"
android:layout_height="match_parent">
<ImageView
android:layout_centerInParent="true"
android:src="#mipmap/ic_save_96"
android:layout_width="#dimen/nav_but_size"
android:layout_height="#dimen/nav_but_size" />
</RelativeLayout>
<TextView
android:background="#ffffff"
android:layout_width="1dp"
android:layout_height="match_parent" />
<RelativeLayout
android:layout_weight="1"
android:id="#+id/new_share"
style="#style/SelectableItemBackground"
android:clickable="true"
android:layout_width="0dp"
android:layout_height="match_parent">
<ImageView
android:layout_centerInParent="true"
android:src="#mipmap/ic_share_96"
android:layout_width="#dimen/nav_but_size"
android:layout_height="#dimen/nav_but_size" />
</RelativeLayout>
<TextView
android:background="#ffffff"
android:layout_width="1dp"
android:layout_height="match_parent" />
<RelativeLayout
android:layout_weight="1"
style="#style/SelectableItemBackground"
android:clickable="true"
android:id="#+id/new_fav"
android:layout_width="0dp"
android:layout_height="match_parent">
<ImageView
android:layout_centerInParent="true"
android:src="#mipmap/ic_hearts_96"
android:layout_width="#dimen/nav_but_size"
android:layout_height="#dimen/nav_but_size"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/ll_adLayout_latest"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
</LinearLayout>
</RelativeLayout>
Thanks a lot :)
You are using circular dependency here :
<LinearLayout
android:background="#color/colorPrimary"
android:id="#+id/pageNavCount"
android:orientation="horizontal"
android:layout_above="#+id/devider"
android:layout_width="match_parent"
android:layout_height="20dp">
and
<View
android:id="#+id/devider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="#+id/pageNavLayout"
android:background="#ffffff" />
you are putting layout_above and layout_below both to the extended view pager put only above or below and try it will solve let me know if its get solved

Error when use android.support.design.widget.CoordinatorLayout

I'm new android dev. I have tried to work with
<android.support.design.widget.CoordinatorLayout>
and here is my XML code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context="com.example.ducbo.flynow_ver20.payment_section">
<LinearLayout
android:id="#+id/payment_header"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#drawable/background_header">
<Button
android:id="#+id/payment_btn_back"
android:layout_width="15dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="15dp"
android:background="#drawable/btnback" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="27dp"
android:layout_toRightOf="#id/payment_btn_back"
android:layout_weight="12"
android:gravity="center_horizontal"
android:text="#string/thanh_toan"
android:textColor="#color/white"
android:textSize="28sp" />
</LinearLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/payment_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/payment_header">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/payment_types"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:padding="15dp"
android:text=""
android:textSize="16sp" />
<LinearLayout
android:id="#+id/payment_types_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/payment_tab_method"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/payment_types">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<!--<android.support.v7.widget.Toolbar-->
<!--android:id="#+id/toolbar"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="?attr/actionBarSize"-->
<!--app:layout_scrollFlags="scroll|enterAlways"-->
<!--app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />-->
<!--android:background="?attr/colorPrimary"-->
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="90dp"
android:background="#color/white"
app:tabGravity="fill"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
<include
android:id="#+id/payment_table_passenger"
layout="#layout/table_passenger"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/payment_types_container"></include>
<include
android:id="#+id/payment_startdp"
layout="#layout/fm_booking_startdp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/payment_table_passenger"></include>
<include
android:id="#+id/payment_enddp"
layout="#layout/fragment_booking_enddp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/payment_startdp">
</include>
<Button
android:id="#+id/payment_btn_submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/payment_enddp"
android:layout_marginBottom="15dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:background="#drawable/border_orange"
android:text="Continue"
android:textColor="#color/white" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
With each tab, I used one fragment to show tab's content. After that, I included some layout below Coordinator but it wasn't appear below Coordinator. When I checked again in Design tab on Android studio, I realized that the height of coordinator seemingly unlimited even though I set wrap_content for it. I think that is problem and I have changed height attribute of Coordinator to specific number and my input layout appeared but I don't want like this. What can I fix the height of Coordinator to wrap content?

Categories