how to align parent bottom in android linear layout? - java

I have a linearlayout
and I want to create at the bottom of it a slice.
I know there are some options, but I'm a bit confused
1) android:layout_gravity:"bottom" --> this doesn't work for me for some reason.
2) android:gravity_weight="0" and give the sibling before it android:gravity_weight:"1"
3) android:height="wrap_content" and give the sibling before it android:height:"match_parent"
I know how to do this using relativeLayout, but I want to practice linearLayout
what would you suggest?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/blue_bg"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="5dp"
android:src="#drawable/signup_illu_why" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=""
android:orientation="horizontal" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/signup_skip_icon" />
</LinearLayout>

Actually, you can set the parent element's gravity to bottom
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/blue_bg"
android:orientation="vertical"
android:gravity="bottom" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="5dp"
android:src="#drawable/signup_illu_why" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=""
android:orientation="horizontal" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/signup_skip_icon" />
</LinearLayout>

<LinearLayout
android:orientation="vertical"
... >
<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<SomeViewThatNeedsGoBottom
... />
</LinearLayout>

try this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</RelativeLayout>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="0.8" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="0.2" />
</LinearLayout>

surround your linear layout with framelayout and give gravity as bottom..
its simple than you think... many layouts are used just for easier move towards design
<FrameLayout
android:layout_height="fill_parent"
android:layout_width = "fill_parent">
<LinearLayout`
android:layout_height="wrap_content"
android:layout_width = "wrap_content"
android:layout_gravity = "bottom"
android:orientation = "vertical">
<Button
android:layout_height="wrap_content"
android:layout_width = "wrap_content"
android:text = "btn"/>
</LinearLayout>
</FrameLayout>
`

Use:
android:gravity="bottom"
example:
<LinearLayout
android:layout_weight="7"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="5">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="some text"
android:layout_weight="2"
android:gravity="bottom" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="some text"
android:layout_weight="1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="some text"android:gravity="center"
android:layout_weight="2" />
</LinearLayout>

Put Relative in LinearLayout
and set Relative to matchparent, so you can use the layoutalignparentbottom
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/blue_bg"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="5dp"
android:src="#drawable/signup_illu_why" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=""
android:orientation="horizontal" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/signup_skip_icon"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</LinearLayout>

Related

In my layout there is recyclerview and bottom navigation bar but navigation bar goes behinf the recycler view

In my layout there is recyclerview and bottom navigation bar but the problem is that the recyclerview occupies all the view and the bottom navigation bar and the header bad goes behind the recycler view. I've sucessfully implemented the material dependency.
this is the layout:
This is the code of the layout.
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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:id="#+id/baseLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<!--status bar-->
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/default_activity_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:backgroundTint="#color/buttoncolor"
app:menu="#menu/default_menu" />
<!--add button-->
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/bottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:backgroundTint="#color/buttoncolor"
app:fabAlignmentMode="end"
app:fabCradleMargin="6.2sp"
app:fabCradleRoundedCornerRadius="15sp"
app:menu="#menu/app_bar_menu" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:backgroundTint="#ED4444"
android:onClick="openCamera"
android:src="#drawable/ic_add"
app:layout_anchor="#id/bottomAppBar"
app:maxImageSize="35sp"
app:tint="#color/white" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rw"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/empty_list" />
<LinearLayout
android:id="#+id/empty_list"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical">
<ImageView
android:id="#+id/empty_list_icon"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#drawable/ic_no_data" />
<TextView
android:id="#+id/empty_list_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="Scan the files"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:textSize="24dp"
android:gravity="center_horizontal"/>
<TextView
android:id="#+id/empty_list_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Scan to make something great"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:gravity="center_horizontal" />
</LinearLayout>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Try this by giving specific height to the BottomAppBar. Then provide margin top and Bottom to the RelativeLayout :
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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:id="#+id/baseLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<!--status bar-->
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/default_activity_button"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="top"
android:backgroundTint="#color/buttoncolor"
app:menu="#menu/default_menu" />
<!--add button-->
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/bottomAppBar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:backgroundTint="#color/buttoncolor"
app:fabAlignmentMode="end"
app:fabCradleMargin="6.2sp"
app:fabCradleRoundedCornerRadius="15sp"
app:menu="#menu/app_bar_menu" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:backgroundTint="#ED4444"
android:onClick="openCamera"
android:src="#drawable/ic_add"
app:layout_anchor="#id/bottomAppBar"
app:maxImageSize="35sp"
app:tint="#color/white" />
<RelativeLayout
android:layout_marginTop="50dp"
android:layout_marginBottom="50dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rw"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/empty_list" />
<LinearLayout
android:id="#+id/empty_list"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical">
<ImageView
android:id="#+id/empty_list_icon"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#drawable/ic_no_data" />
<TextView
android:id="#+id/empty_list_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="Scan the files"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:textSize="24dp"
android:gravity="center_horizontal"/>
<TextView
android:id="#+id/empty_list_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Scan to make something great"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:gravity="center_horizontal" />
</LinearLayout>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

Linear layout overlapping another linear layout

I have two LinearLayouts in a RelativeLayout the problem is that the top linear layout is overlapping the bottom one a little bit.I tried everything. Please Somebody help me.Below is my XML File
Or tell me how to do it programmatically. Like subtracting height of one linear layout from another.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1">
<FrameLayout
android:id="#+id/page_fragment"
android:layout_width="150dp"
android:layout_height="match_parent"
android:background="#color/spinner_text_color" />
<FrameLayout
android:id="#+id/detail_fragment"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#color/white_bg"
android:layout_weight="1"></FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/spinner_text_color">
<Button
android:id="#+id/filterResetButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".50"
android:textColor="#color/white_bg"
android:textAllCaps="false"
android:background="#drawable/light_button_click"
android:text="Reset All" />
<Button
android:id="#+id/filterApplyButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".50"
android:textAllCaps="false"
android:background="#drawable/submit_order_click"
android:textColor="#color/white_bg"
android:text="Apply" />
</LinearLayout>
</RelativeLayout>
Try this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1"
android:layout_above="#+id/linearLayout">
<FrameLayout
android:id="#+id/page_fragment"
android:layout_width="150dp"
android:layout_height="match_parent"
android:background="#color/colorPrimary" />
<FrameLayout
android:id="#+id/detail_fragment"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#color/white"
android:layout_weight="1"></FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary"
android:id="#+id/linearLayout">
<Button
android:id="#+id/filterResetButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".50"
android:textColor="#color/white"
android:textAllCaps="false"
android:background="#drawable/ic_authy"
android:text="Reset All" />
<Button
android:id="#+id/filterApplyButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".50"
android:textAllCaps="false"
android:background="#drawable/ic_arrow_32"
android:textColor="#color/white"
android:text="Apply" />
</LinearLayout>
</RelativeLayout>
Use Relative Layout properties like
layout_below and layout_above
Try following code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/bottomLayout"
android:orientation="horizontal"
android:weightSum="1">
<FrameLayout
android:id="#+id/page_fragment"
android:layout_width="150dp"
android:layout_height="match_parent"
android:background="#color/spinner_text_color" />
<FrameLayout
android:id="#+id/detail_fragment"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#color/white_bg"
android:layout_weight="1"></FrameLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/bottomLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/spinner_text_color">
<Button
android:id="#+id/filterResetButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".50"
android:textColor="#color/white_bg"
android:textAllCaps="false"
android:background="#drawable/light_button_click"
android:text="Reset All" />
<Button
android:id="#+id/filterApplyButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".50"
android:textAllCaps="false"
android:background="#drawable/submit_order_click"
android:textColor="#color/white_bg"
android:text="Apply" />
</LinearLayout>
</RelativeLayout>
If the layouts are large and can't be accommodated in a single a screen then you should wrap both the linear layouts in a scrollView. Let me know if you face problem in using scrollView.
This is very easy you just have to set id to the Linear Layout at bottom like
**android:id="#+id/bottom_linearlayout"**
and set the upper Linear Layout "above" over the bottom ones "id", like this
**android:layout_above="#id/bottom_linearlayout"**
`<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_above="#id/bottom_linearlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1">
<FrameLayout
android:id="#+id/page_fragment"
android:layout_width="150dp"
android:layout_height="match_parent"
android:background="#color/spinner_text_color" />
<FrameLayout
android:id="#+id/detail_fragment"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#color/white_bg"
android:layout_weight="1"></FrameLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/bottom_linearlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/spinner_text_color">
<Button
android:id="#+id/filterResetButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".50"
android:textColor="#color/white_bg"
android:textAllCaps="false"
android:text="Reset All" />
<Button
android:id="#+id/filterApplyButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".50"
android:textAllCaps="false"
android:textColor="#color/white_bg"
android:text="Apply" />
</LinearLayout>
</RelativeLayout>`
you parent layout is linear layout so child is overlap each other
use my code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1"
android:layout_weight="90">
<FrameLayout
android:id="#+id/page_fragment"
android:layout_width="150dp"
android:layout_height="match_parent"
android:background="#color/spinner_text_color" />
<FrameLayout
android:id="#+id/detail_fragment"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#color/white_bg"
android:layout_weight="1"></FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:layout_alignParentBottom="true"
android:background="#color/spinner_text_color">
<Button
android:id="#+id/filterResetButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".50"
android:textColor="#color/white_bg"
android:textAllCaps="false"
android:background="#drawable/light_button_click"
android:text="Reset All" />
<Button
android:id="#+id/filterApplyButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".50"
android:textAllCaps="false"
android:background="#drawable/submit_order_click"
android:textColor="#color/white_bg"
android:text="Apply" />
</LinearLayout>
</LinearLayout>

XML layout 2 views in centre, one at top

I created linearlayout with two buttons in center (buttons 1 and 2), but I can't manage it to create the view 3 on top, which I need to make it fill whole width and adjust it's height by it (keep proportions). How do I create third view?
Image:
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<LinearLayout
android:orientation="vertical"
android:layout_gravity="center_vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content" >
<ImageButton
android:background="#drawable/btn_one"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1.0" />
<ImageButton
android:background="#drawable/btn_second"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1.0" />
</LinearLayout>
I would recommend you use relative layouts, they are the closest thing in android to an "absolute layout" replace the button tags with Image button tags
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
</RelativeLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button2"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="215dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button3"
android:layout_below="#+id/button2"
android:layout_alignStart="#+id/button2" />
</RelativeLayout>
try this code set height and width what size of image button you need and simple look what you need.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageButton
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:orientation="vertical"
android:gravity="center">
<ImageButton
android:layout_width="200dp"
android:layout_height="50dp"/>
<ImageButton
android:layout_width="200dp"
android:layout_height="50dp" />
</LinearLayout>

GridView title and date orientation

I want my title and date text views to appear at the bottom of the image instead of the top where they currently are. I want them to overlap the image like they are at the moment but then have the title then date underneath with the same background so they appear to be in the same "box"
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#55000000"
android:orientation="vertical"
>
<uk.ac.kent.sc580.edanews.GridViewItem
android:id="#+id/listImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
<TextView
android:id="#+id/listTitle"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textColor="#android:color/white"
android:background="#3183b9"
android:ellipsize="end"
android:maxLines="2" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/listDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/white" />
</LinearLayout>
</FrameLayout>
Use the RelativeLayout instead
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#55000000">
<uk.ac.kent.sc580.edanews.GridViewItem
android:id="#+id/listImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical
android:layout_alignParentBottom="true">
<TextView
android:id="#+id/listTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/listDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/white" />
</LinearLayout>
</RelativeLayout>

Floating Action Button between two tabs

I have a fab and would like to have it during the passage between two tabs, tried to put the transparent background in fragment_main.xml but without success. The problem is really how do I put the background of the two fragments appearing while allowing this gray stripe cutting because of FAB. Very grateful to those who help me.
fragment_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0000"
android:orientation="vertical">
<br.com.test.common.view.SlidingTabLayout
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="#0000"/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="#+id/pink_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_icon="#drawable/ic_add"
fab:fab_colorNormal="#color/material_orange_500"
fab:fab_colorPressed="#color/material_orange_a200"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom|right"
android:layout_marginBottom="16dp"/>
</LinearLayout>
fragment_profile.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="?android:attr/colorBackground"
android:layout_weight="1"
android:gravity="center_horizontal">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<ImageView
android:id="#+id/profileImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_launcher"
android:padding="10dp"
android:scaleType="centerInside"/>
<TextView
android:id="#+id/profileName"
android:layout_below="#id/profileImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="teste"
android:textSize="22sp"/>
<LinearLayout
android:id="#+id/ll_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/profileName"
android:padding="10dp">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="150dp"
card_view:cardCornerRadius="4dp">
<TextView
android:id="#+id/info_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="teste"/>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/ll_1"
android:padding="10dp">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view_2"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="150dp"
card_view:cardCornerRadius="4dp">
<TextView
android:id="#+id/info_text2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="teste"/>
</android.support.v7.widget.CardView>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
fragment_service.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center_vertical">
<TableRow>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imgDP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#drawable/logo_dp"/>
<TextView
android:layout_below="#id/imgDP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DP"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp">
<ImageView
android:id="#+id/imgNA1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#drawable/logo_na"/>
<TextView
android:layout_below="#id/imgNA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NA"/>
</RelativeLayout>
</TableRow>
</TableLayout>
</LinearLayout>
Eihschnaehkeee is right -- you just need a layout that allows overlapping. Here is XML to try (also adding right margin for your button):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0000">
<br.com.test.common.view.SlidingTabLayout
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/sliding_tabs"
android:layout_alignParentBottom="true"
android:background="#0000"/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="#+id/pink_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_icon="#drawable/ic_add"
fab:fab_colorNormal="#color/material_orange_500"
fab:fab_colorPressed="#color/material_orange_a200"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"/>
</RelativeLayout >
Eihschnaehkeee and Bruce.
I tried to put as relative layout and swipe funcinou not more, I tried using SlidingTabLayout the android code https://github.com/googlesamples/android-SlidingTabsBasic/

Categories