I'm trying to put 2 layouts on top of each others but it doesn't work.There is a space that i don't know how to remove.
here is my code:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom|center"
android:weightSum="1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="170dp"
android:layout_weight="0.5"
android:background="#drawable/column_white"
android:layout_gravity="bottom|center"
android:gravity="bottom"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="10sp"
android:layout_height="100sp"
android:background="#drawable/arrow_body"
android:layout_marginLeft="10sp"
></LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/arrow_shape"
android:layout_marginLeft="6sp"
></LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="150dp"
android:layout_margin="25sp"
android:background="#drawable/column_blue"
android:gravity="center"
android:layout_weight="0.5" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="40 000 "
android:textColor="#ffffff"
android:textSize="25sp" />
</LinearLayout>
</LinearLayout>
with RelativeLayout:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="170dp"
android:background="#drawable/column_white"
android:gravity="bottom"
android:layout_alignBottom="#id/second_part"
android:orientation="vertical" >
<LinearLayout
android:layout_width="10sp"
android:layout_height="100sp"
android:layout_marginLeft="10sp"
android:background="#drawable/arrow_body" >
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6sp"
android:background="#drawable/arrow_shape" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/second_part"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:layout_margin="25sp"
android:background="#drawable/column_blue"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="40 000"
android:textColor="#ffffff"
android:textSize="25sp" />
</LinearLayout>
</RelativeLayout>
Use Relative layout to place views on top of each other , like this
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:background="#f00"
android:orientation="vertical"
android:weightSum="1" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="170dp"
android:layout_centerInParent="true"
android:layout_gravity="bottom|center"
android:background="#fff"
android:gravity="bottom"
android:orientation="vertical" >
<LinearLayout
android:layout_width="10dp"
android:layout_height="100sp"
android:layout_centerInParent="true"
android:layout_marginLeft="10sp"
android:background="#37c100" >
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6sp"
android:background="#drawable/arrow_shape" >
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="150dp"
android:layout_centerInParent="true"
android:layout_margin="25sp"
android:layout_weight="0.5"
android:background="#0000ff"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="40 000 "
android:textColor="#ffffff"
android:textSize="25sp" />
</LinearLayout>
</RelativeLayout>
In your second LinearLayout, you have a android:layout_margin="25sp".
Remove this line or at least don't set a marginTop.
This can now also be done using a constraintlayout. In my use case I had a RecyclerView that when empty had to be "covered" by a text and a button to allow users to add items to the list. (Part of the Big Nerd Ranch programming book, challenge 13.3)
Code is as follows (change to your own needs):
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/no_crimes_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/no_crimes_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="#string/no_crimes"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/recyclerView"
app:layout_constraintStart_toStartOf="#+id/recyclerView"
app:layout_constraintTop_toTopOf="#+id/recyclerView" />
<Button
android:id="#+id/new_crime_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="#string/new_crime"
app:layout_constraintBottom_toBottomOf="#+id/recyclerView"
app:layout_constraintEnd_toEndOf="#+id/recyclerView"
app:layout_constraintStart_toStartOf="#+id/recyclerView"
app:layout_constraintTop_toBottomOf="#+id/textView" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/crime_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.constraint.ConstraintLayout>
Related
I have a massive space (almost the entire rest of the screen - not complete) below each of my RecyclerView entries, and I have no idea what could be causing it. I have one LinearLayout with weights, but that's contained within another LinearLayout of a fixed height (as shown in the code below). Here is my EntryItem layout, as well as my host layout (Fragment):
Entry Item Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="675dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:weightSum="5"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="7">
<android.support.v7.widget.CardView
android:id="#+id/top_card"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="-10dp"
android:layout_weight="2"
app:cardBackgroundColor="#color/redditOrange"
app:cardCornerRadius="10dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.constraint.Guideline
android:id="#+id/top_card_vert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.075" />
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginLeft="4dp"
android:layout_marginTop="4dp"
app:srcCompat="#drawable/reddit"
app:layout_constraintRight_toLeftOf="#id/top_card_vert"/>
<TextView
android:id="#+id/label"
android:layout_width="349dp"
android:layout_height="20dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="4dp"
android:fontFamily="#font/volte_regular"
android:gravity="center_vertical"
android:text="r/tifu"
app:layout_constraintStart_toEndOf="#id/top_card_vert"
android:textColor="#ffffff" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/main_card"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
app:cardBackgroundColor="#color/cardColor"
app:cardElevation="7dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.Guideline
android:id="#+id/card_title_line"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.2" />
<TextView
android:paddingTop="2dp"
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_marginLeft="4dp"
android:layout_marginTop="4dp"
android:fontFamily="#font/volte_bold"
android:text="TIFU by trying to buy a Christmas present for my wife"
app:layout_constraintBottom_toTopOf="#+id/card_title_line"
android:textColor="#color/offBlack" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Using ConstraintLayouts to do percents are recommended instead of using nested weights (LinearLayouts) -->
<android.support.constraint.Guideline
android:id="#+id/hor_guideline_below"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="73dp" />
<android.support.constraint.Guideline
android:id="#+id/above_text_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.27" />
<android.support.constraint.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.constraint.Guideline
android:id="#+id/ver_guideline_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.32" />
<android.support.constraint.Guideline
android:id="#+id/hor_guideline_above"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.38" />
<TextView
android:id="#+id/author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/volte_regular"
android:gravity="center_vertical"
android:paddingTop="7dp"
android:paddingBottom="1dp"
android:text="/u/TheFiveHundred"
android:textColor="#color/darkRedditOrange"
android:textSize="10sp"
app:layout_constraintLeft_toRightOf="#id/ver_guideline_subtitle"
app:layout_constraintTop_toBottomOf="#id/hor_guideline_above" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="#id/author"
app:layout_constraintEnd_toStartOf="#id/date_created"
app:layout_constraintLeft_toRightOf="#id/ver_guideline_subtitle"
app:layout_constraintTop_toBottomOf="#id/hor_guideline_above"
android:paddingTop="5dp"
android:textColor="#color/darkRedditOrange"
android:textSize="10sp"
android:text="|"/>
<TextView
android:id="#+id/date_created"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="116dp"
android:fontFamily="#font/volte_regular"
android:gravity="center_vertical"
android:paddingBottom="1dp"
android:paddingTop="7dp"
android:text="12.12.2018"
android:textColor="#color/darkRedditOrange"
android:textSize="10sp"
app:layout_constraintLeft_toRightOf="#id/ver_guideline_subtitle"
app:layout_constraintTop_toBottomOf="#id/hor_guideline_above" />
</android.support.constraint.ConstraintLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_gravity="bottom">
<ImageView
android:id="#+id/thumbnail"
android:layout_width="63dp"
android:layout_height="63dp"
android:layout_gravity="bottom"
android:layout_marginStart="4dp"
android:layout_marginBottom="3dp"
android:tint="#color/redditOrange"
app:srcCompat="#mipmap/ic_launcher" />
<TextView
android:id="#+id/textContent"
android:layout_width="304dp"
android:layout_height="63dp"
android:layout_gravity="bottom|end"
android:layout_marginEnd="8dp"
android:fontFamily="#font/volte_regular"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:text="#string/lorem_ipsum"
android:textColor="#color/darkGray"
android:textSize="12sp"
app:layout_constraintBottom_toTopOf="#+id/hor_guideline_below"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/thumbnail"
app:layout_constraintTop_toBottomOf="#id/above_text_content"
app:layout_constraintVertical_bias="0.0" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
Fragment Layout (Host)
<?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.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Any assistance would be greatly appreciated.
Remove
android:weightSum="5"
from the parent LinearLayout.
Also, do you need this fixed height?:
android:layout_height="675dp"
Layout wrap content not working
Below is my XML code . I want to place the portion linear layout with grey colour just above the main image . Screenshot of my code here.
In devices with aspect ratio 16:9 design is correct , but in 18:9 and 18.5:9 the grey portion is on top side .
The topic text and icon must be top left side portion of main image .
The design i want here
Never mind top side . From bottom the hight must be wrap the size of image
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:background="#color/light_green"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/dark_green">
<LinearLayout
android:id="#+id/topLin"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#color/grey"
android:orientation="horizontal">
<TextView
android:id="#+id/nameTxt"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:ellipsize="end"
android:gravity="center|start"
android:maxLength="25"
android:singleLine="true"
android:text="Abin Stanly"
android:textColor="#color/white"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:adjustViewBounds="true"
android:src="#drawable/test" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#id/imageView"
android:layout_marginStart="20dp"
android:layout_marginTop="15dp">
<ImageView
android:id="#+id/icon"
android:layout_width="#dimen/icon_height"
android:layout_height="#dimen/icon_height"
android:layout_gravity="center"
android:src="#drawable/ic_love" />
<TextView
android:id="#+id/topicTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:gravity="center"
android:paddingEnd="10dp"
android:shadowColor="#color/grey"
android:shadowDx=".5"
android:shadowDy=".5"
android:shadowRadius="3.5"
android:text="Topic"
android:textColor="#color/white"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Here the main layout is RelativeLayout and the children are both layout_alignParentBottom="true"
You can just switch the child layouts around until you get the required layout
Tip: The less layouts you use, the faster rendering will be on slow devices.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/light_green">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/grey">
<TextView
android:id="#+id/nameTxt"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:ellipsize="end"
android:gravity="center|start"
android:maxLength="25"
android:singleLine="true"
android:text="Abin Stanly"
android:textColor="#color/white"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<ImageView
android:id="#+id/icon"
android:layout_width="#dimen/icon_height"
android:layout_height="#dimen/icon_height"
android:layout_gravity="center"
android:src="#drawable/ic_love" />
</LinearLayout>
</RelativeLayout>
I have added weightSum to parent LinearLayout so you can easily divide screen according to your requirements.
Assigned View android:layout_weight="3" so it will cover 3/10th part of the screen, you can change it according to what you feels good for you.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:background="#android:color/holo_green_light"
android:orientation="vertical"
android:weightSum="10"
xmlns:android="http://schemas.android.com/apk/res/android">
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:background="#android:color/holo_green_light"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="7">
<TextView
android:id="#+id/nameTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLength="25"
android:padding="11dp"
android:background="#android:color/darker_gray"
android:text="Abin Stanly"
android:textColor="#android:color/white"
android:textStyle="bold" />
<RelativeLayout
android:id="#+id/RelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/nameTxt"
android:layout_alignParentBottom="true"
>
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:scaleType="centerCrop"
android:src="#drawable/mobile_world" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#id/imageView"
android:background="#android:color/black"
android:padding="11dp"
>
<ImageView
android:id="#+id/icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:src="#drawable/back_arrow" />
<TextView
android:id="#+id/topicTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:gravity="center"
android:paddingEnd="10dp"
android:shadowColor="#android:color/darker_gray"
android:shadowDx=".5"
android:shadowDy=".5"
android:shadowRadius="3.5"
android:layout_gravity="center_vertical"
android:text="Topic"
android:textColor="#android:color/white"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
Output
Check this layout:
<?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="#android:color/holo_green_light">
<TextView
android:id="#+id/nameTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/imageView"
android:background="#android:color/darker_gray"
android:maxLength="25"
android:padding="10dp"
android:text="Abin Stanly"
android:textColor="#android:color/white"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:scaleType="centerCrop"
android:src="#drawable/test" />
<TextView
android:id="#+id/topicTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageView"
android:layout_gravity="center_vertical"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:drawableStart="#drawable/ic_love"
android:drawablePadding="10dp"
android:gravity="center"
android:paddingEnd="10dp"
android:shadowColor="#android:color/darker_gray"
android:shadowDx=".5"
android:shadowDy=".5"
android:shadowRadius="3.5"
android:text="Topic"
android:textColor="#android:color/white"
android:textStyle="bold" />
</RelativeLayout>
I have a RecyclerView that automatically adds a marginBottom to its childrens.
I already tried to put zero margins in XML and set 0 marginBottom programatically.
Android set these margins afeter onBindView of Adapter.
Its Like you can see in the image.
EDIT: Thats the XML file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="#+id/message_processo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#fff"
app:cardCornerRadius="5dp"
android:elevation="2dp"
android:orientation="vertical"
app:cardBackgroundColor="#color/white">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<br.com.isilist.android.view.widget.SquareImageView
android:id="#+id/iv_product_image"
android:src="#drawable/default_product_open_screen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:adjustViewBounds="true"/>
<View
android:layout_below="#+id/iv_product_image"
android:layout_above="#+id/container_bottom"
android:id="#+id/middle_separator"
android:layout_width="match_parent"
android:layout_height="1px"/>
<RelativeLayout
android:layout_below="#+id/iv_product_image"
android:id="#+id/container_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:paddingLeft="5dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tv_name"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:textSize="16sp"
android:text="Teste"
android:layout_marginBottom="#dimen/pad_5dp"
android:textColor="#color/dark_gray"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="4dp"
android:id="#+id/rl_sale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/red_button">
<TextView
android:textSize="12sp"
android:textColor="#fff"
android:layout_margin="3dp"
android:text="#string/sale"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<TextView
android:id="#+id/tv_unit_price"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:textSize="13sp"
android:layout_marginBottom="#dimen/pad_5dp"
android:textColor="#888"
android:text="Teste"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/rl_bottom_layout_list_product">
<LinearLayout
android:id="#+id/ll_info_quantity_price"
android:layout_centerVertical="true"
android:orientation="vertical"
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_marginLeft="8dp"
android:layout_marginStart="#dimen/pad_8dp"
android:layout_marginRight="#dimen/pad_8dp"
android:layout_marginEnd="#dimen/pad_8dp"
android:background="#888"
android:layout_width="match_parent"
android:layout_height="1px"/>
<TextView
android:id="#+id/tv_item_quantity"
android:textSize="13sp"
android:textColor="#888"
android:text="Quantidade: 12"
android:layout_marginTop="#dimen/pad_4dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:textSize="13sp"
android:textColor="#color/primary_color"
android:text="R$"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/tv_item_total_price"
android:textSize="#dimen/txt_18sp"
android:textColor="#color/primary_color"
android:text="148.99"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_marginBottom="-30dp"
android:layout_alignBottom="#+id/middle_separator"
android:id="#+id/ll_add_remove_item"
android:orientation="horizontal"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_toLeftOf="#+id/container_add_quantity"
android:layout_toStartOf="#+id/container_add_quantity"
android:elevation="3dp"
android:layout_margin="#dimen/pad_16dp"
android:id="#+id/container_deduct_quantity"
android:background="#drawable/circle_background_orange_white_stroke"
android:layout_width="#dimen/pad_35dp"
android:layout_height="#dimen/pad_35dp">
<ImageView
android:src="#drawable/ic_minus_white_48dp"
android:layout_centerInParent="true"
android:layout_width="#dimen/pad_30dp"
android:layout_height="#dimen/pad_30dp" />
</RelativeLayout>
<RelativeLayout
android:elevation="3dp"
android:layout_marginBottom="-30dp"
android:id="#+id/container_add_quantity"
android:layout_margin="#dimen/pad_16dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#drawable/circle_background_orange_white_stroke"
android:layout_width="#dimen/pad_35dp"
android:layout_height="#dimen/pad_35dp">
<ImageView
android:src="#drawable/ic_plus_white_48dp"
android:layout_centerInParent="true"
android:layout_width="#dimen/pad_30dp"
android:layout_height="#dimen/pad_30dp" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_badge"
android:layout_marginBottom="-12dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="#dimen/pad_16dp"
android:layout_alignBottom="#+id/middle_separator"
android:background="#drawable/circle_background_green"
android:layout_width="25dp"
android:layout_height="25dp">
<ImageView
android:id="#+id/iv_icon_badge_product"
android:src="#drawable/ic_check_white_48dp"
android:layout_centerInParent="true"
android:layout_width="20dp"
android:layout_height="20dp" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
There is a way to not allow RecyclerView to do that?
Two sources of this issue might be:
android:dividerHeight="" of your RecyclerView is too large. (In this case the last item doesn't have a bottom margin.)
Items themselves have their own bottom margin. (In this case all items have bottom margin.)
Hi, I commented that I have this layout and if you can see there is a line on the right which should go below the text
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_promocion_item0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#363636"
android:padding="10dip" >
<LinearLayout
android:id="#+id/contenido"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<LinearLayout
android:id="#+id/contenido_Nombre"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".75"
android:orientation="horizontal"
>
<TextView
android:id="#+id/nombre_promo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Vodka + Nectar"
android:textColor="#ffffff"
android:textSize="25sp"
android:tag="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/contenido_precio"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:orientation="horizontal" >
<ImageView
android:id="#+id/separador_lateral"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:src="#drawable/vertical"
android:layout_gravity="left"/>
<TextView
android:id="#+id/precio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$2200"
android:textColor="#ffffff"
android:textSize="24dp"
/>
</LinearLayout>
<ImageView
android:id="#+id/separador"
android:layout_width="0dp"
android:layout_height="19dp"
android:layout_weight=".50"
android:src="#drawable/divierblanco"
android:layout_alignParentLeft="true"/>
</LinearLayout>
</LinearLayout>
.. so is something like:
NAME: PRICE
I can not locate the image below the text .... Can you help me?
You have way too many nested LinearLayouts, IMHO, which can be bad for performance and decrease readability. I would use a RelativeLayout and 1 nested LinearLayout
<RelativeLayout
...>
<LinearLayout
android:id="#+id/someId"
....
<TextView
...>
<ImageView
...>
<TextView
...>
</LinearLayout>
<ImageView
android:layout_below="id/someId"
...>
Something like this should work.
Alternatively if this doesn't work for you, then placing that ImageVIew outside of the first child LinearLayout should also work
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_promocion_item0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#363636"
android:padding="10dip" >
<LinearLayout
android:id="#+id/contenido"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/contenido_Nombre"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".75"
android:orientation="horizontal" >
<TextView
android:id="#+id/nombre_promo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Vodka + Nectar"
android:textColor="#ffffff"
android:textSize="25sp"
android:tag="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/contenido_precio"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:orientation="horizontal" >
<ImageView
android:id="#+id/separador_lateral"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:src="#drawable/vertical"
android:layout_gravity="left"/>
<TextView
android:id="#+id/precio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$2200"
android:textColor="#ffffff"
android:textSize="24dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="#+id/separador"
android:layout_width="0dp"
android:layout_height="19dp"
android:layout_weight=".50"
android:src="#drawable/divierblanco"
android:layout_alignParentLeft="true"/> // this doesn't do anything in a LinearLayout
</LinearLayout>
Your imageView (with the id separador) is inside a linearLayout with an orientation set to "horizontal". Move the imageView to the outermost linearlayout like so:
EDIT: The xml that's displayed below is completely different than what I typed in my answer. What's up with that? Regardless, move the imageView down an element.
<LinearLayout
android:id="#+id/contenido"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/contenido_Nombre"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".75"
android:orientation="horizontal" >
<TextView
android:id="#+id/nombre_promo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:tag="bold"
android:text="Vodka + Nectar"
android:textColor="#ffffff"
android:textSize="25sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/contenido_precio"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:orientation="horizontal" >
<ImageView
android:id="#+id/separador_lateral"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="left"
android:src="#drawable/vertical" />
<TextView
android:id="#+id/precio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$2200"
android:textColor="#ffffff"
android:textSize="24dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="#+id/separador"
android:layout_width="0dp"
android:layout_height="19dp"
android:layout_alignParentLeft="true"
android:layout_weight=".50"
android:src="#drawable/divierblanco" /></LinearLayout>
i am working on a layout with 3 buttons and an image view i call the imageview as the first child of the parent however when i build it on actual device the imageview goes down after the buttons... really weird....
heres the xml file:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/title_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/111"
android:visibility="visible" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/222"
android:visibility="visible"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_medium"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/highscores_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/highscore_btn"
android:visibility="visible" />
<Button
android:id="#+id/more_apps_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin_medium"
android:background="#drawable/333"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
is this because of the size of the imageview? it is really large so i put it in xxhdpi folder so it will be reduced. any thoughts? thanks
// try this
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<ImageView
android:id="#+id/title_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/111"
android:visibility="visible" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/222"
android:visibility="visible"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_medium"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/highscores_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/highscore_btn"
android:visibility="visible" />
<Button
android:id="#+id/more_apps_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin_medium"
android:background="#drawable/333"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>
</FrameLayout>