Android XML Insert a layout on another layout - android

I am developing a screen that allows the user to create a post:
here
I want that when the user clicks on the cardview of the plus, a relative layout opens that through a recyclerview shows the various types of films, and the same thing for the other cardview with the genres of films. I don't know how to insert a layout into another layout and then use your own objects. What should I do, create an overlapping layout or do something else? I can't superimpose another layout on mine,
beacuse this happens
As you can see the related layout is below the main cardview. How could I put it on top?
Full Code:
<?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"
tools:context=".userProfile">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="-37dp"
android:backgroundTint="#EFE8AB"
app:cardCornerRadius="40dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/txtVal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Valutazione"
android:textColor="#color/black"
android:fontFamily="#font/amiko"
android:textSize="25dp"
android:layout_marginTop="230dp"
android:layout_alignStart="#+id/img_imgpost"
/>
<androidx.cardview.widget.CardView
android:id="#+id/imBackReg"
android:layout_width="65dp"
android:layout_height="68dp"
app:cardCornerRadius="25dp"
android:layout_marginRight="8dp"
android:layout_alignParentEnd="true"
android:layout_marginTop="60dp"
android:backgroundTint="#color/redButton2">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_baseline_close_24"
/>
</androidx.cardview.widget.CardView>
<TextView
android:id="#+id/d"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Descrizione:"
android:textColor="#color/black"
android:fontFamily="#font/amiko"
android:textSize="25dp"
android:layout_marginTop="295dp"
android:layout_alignStart="#+id/img_imgpost"
/>
<EditText
android:id="#+id/txt_desc"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginRight="20dp"
android:layout_marginTop="330dp"
android:background="#color/primaryPopHome2"
android:ems="10"
android:backgroundTint="#EFE8AB"
android:gravity="top|left"
android:hint="Descrizione"
android:layout_alignStart="#+id/txtVal"
android:inputType="textMultiLine"
android:textColor="#color/black"
android:textColorHint="#b7b7b7"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="450dp"
android:layout_marginHorizontal="15dp"
android:background="#color/darkpost"/>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginTop="470dp"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txtT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tipologia:"
android:textColor="#color/black"
android:fontFamily="#font/amiko"
android:textSize="25dp"
android:layout_marginLeft="2dp"
android:layout_centerVertical="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:text="Tipologia scelta"
android:layout_marginTop="45dp"
android:layout_marginLeft="3dp"
/>
<androidx.cardview.widget.CardView
android:id="#+id/chooseTip"
android:layout_width="65dp"
android:layout_height="68dp"
app:cardCornerRadius="20dp"
android:layout_marginLeft="8dp"
android:layout_toEndOf="#+id/txtT"
android:layout_centerVertical="true"
android:backgroundTint="#color/darkpost">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_baseline_add_24"/>
</androidx.cardview.widget.CardView>
<TextView
android:id="#+id/txtC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Categoria:"
android:layout_centerVertical="true"
android:textColor="#color/black"
android:fontFamily="#font/amiko"
android:textSize="25dp"
android:layout_marginLeft="10dp"
android:layout_toEndOf="#+id/chooseTip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:text="Categoria scelta"
android:layout_marginTop="45dp"
android:layout_alignStart="#id/txtC"
android:layout_marginLeft="2dp"
/>
<androidx.cardview.widget.CardView
android:id="#+id/chooseCat"
android:layout_width="65dp"
android:layout_height="68dp"
app:cardCornerRadius="20dp"
android:layout_marginLeft="8dp"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/txtC"
android:backgroundTint="#color/darkpost">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_baseline_add_24"/>
</androidx.cardview.widget.CardView>
</RelativeLayout>
</HorizontalScrollView>
<EditText
android:id="#+id/txt_valuta"
android:layout_width="50dp"
android:layout_height="46dp"
android:layout_marginTop="220dp"
android:layout_marginLeft="13dp"
android:layout_centerHorizontal="true"
android:background="#drawable/textview_new_style"
android:ems="10"
android:hint="0"
android:text=""
android:textSize="25dp"
android:textAlignment="center"
android:layout_toEndOf="#+id/txtVal"
android:textColor="#color/black"
android:textColorHint="#EFE8AB"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/10"
android:textSize="25dp"
android:textColor="#color/black"
android:layout_marginTop="225dp"
android:layout_marginLeft="5dp"
android:layout_toEndOf="#+id/txt_valuta"
/>
<androidx.cardview.widget.CardView
android:id="#+id/img_imgpost"
android:layout_width="140dp"
android:layout_height="150dp"
app:cardCornerRadius="30dp"
android:layout_marginLeft="20dp"
android:layout_alignParentTop="true"
android:layout_marginTop="50dp"
android:backgroundTint="#color/darkpost">
<ImageView
android:id="#+id/imgPostICV"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#color/darkpost"/>
</androidx.cardview.widget.CardView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Titolo:"
android:textColor="#color/black"
android:fontFamily="#font/amiko"
android:textSize="25dp"
android:layout_marginTop="567dp"
android:layout_alignStart="#+id/img_imgpost"
/>
<EditText
android:id="#+id/txt_titoloo"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="600dp"
android:layout_marginHorizontal="5dp"
android:backgroundTint="#color/darkpost"
android:ems="10"
android:hint="Titolo"
android:layout_marginBottom="20dp"
android:inputType="textEmailAddress"
android:textColor="#color/black"
android:textColorHint="#b7b7b7"
android:layout_alignStart="#+id/d"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/btn_invia"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginTop="660dp"
app:cardCornerRadius="15dp"
android:layout_marginBottom="10dp"
android:layout_marginHorizontal="20dp"
android:backgroundTint="#E8E1A2"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pubblica il Post"
android:textColor="#color/black"
android:layout_centerInParent="true"
android:textSize="30dp"
android:fontFamily="#font/amiko"
android:textStyle="bold"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black"/>
</RelativeLayout>

This example could solve your problem
fragment_main.xml
<?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" >
<include
android:id="#+id/innerLayout"
layout="#layout/inner_layout" />
</RelativeLayout>
inner_layout.xml
<?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:id="top_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="inner text" />
</RelativeLayout>
Now in your MainFragment class
Depending on your need you can set the visibility of the inner_layout by using the following code snippet
View innerLayout = findViewById(R.id.innerLayout);
//For hiding the innner layout dynamically
innerLayout.top_layout.setVisibility(View.GONE);
//For showing the innner layout dynamically
innerLayout.top_layout.setVisibility(View.VISIBLE);
//to set text in TextView
innerLayout.text.setText("Anything you want");

Related

Persist corner radius of a CardView on setting background of a layout inside that CardView

I've a CardView with some corner radius inside which are three relative layouts. When I set background of the layout whose top is aligned with the top of CardView, corner radius is lost.
How to keep corner radius?
Code:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:layout_centerHorizontal="false"
android:layout_centerInParent="true"
app:cardCornerRadius="10dp"
android:clipToPadding="true"
app:cardPreventCornerOverlap="false">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/rlBase"
android:clipChildren="true"
android:clipToPadding="true"
android:animateLayoutChanges="false">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="#+id/rlOverallPerformance"
android:background="#color/lightBlue"
android:clipToPadding="false"
android:clipChildren="false">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="#+id/rlRealizedValue"
android:layout_below="#+id/rlOverallPerformance">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="#+id/rlUnrealizedValue"
android:layout_below="#+id/rlRealizedValue"
android:elevation="1dp">
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
Surround your CardView with other ViewGroup element like FrameLayout, LinearLayout or RelativeLayout. Even I faced same problem, then it worked this way. I read it somewhere.
File: listitem_screen.xml
<?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="wrap_content">
<include layout="#layout/listitem_screen_base" />
</RelativeLayout>
I am using <include> tag as I am using same layout at different places.
File: listitem_screen_base.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardBackgroundColor="#color/windowBackground"
app:cardCornerRadius="#dimen/rect_corner_radius"
app:cardElevation="#dimen/cardview_default_elevation"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true">
<LinearLayout
android:id="#+id/ll_base"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.company.app.custom.CustomImageView
android:id="#+id/img_poster"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#color/black3"
app:calculation_type="height"
app:ratio_height="#integer/inspire_img_height_ratio"
app:ratio_width="#integer/inspire_img_width_ratio"
app:riv_corner_radius_top_left="#dimen/rect_corner_radius"
app:riv_corner_radius_top_right="#dimen/rect_corner_radius" />
<com.company.app.custom.FontTextView
android:id="#+id/lbl_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="20dp"
android:background="#drawable/shape_rect_round_border_right_yellow_fill"
android:paddingBottom="2dp"
android:paddingEnd="6dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:paddingStart="6dp"
android:paddingTop="2dp"
android:text="#string/s_new"
android:textColor="?android:attr/textColorPrimary"
android:textSize="9.72sp"
app:customFont="#string/font_circular_book" />
</FrameLayout>
<com.company.app.custom.FontTextView
android:id="#+id/lbl_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:layout_marginBottom="13dp"
android:layout_marginEnd="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="15dp"
android:ellipsize="end"
android:gravity="center_vertical|start"
android:maxLines="2"
android:minHeight="38dp"
android:textAlignment="viewStart"
android:textColor="?android:textColorPrimaryInverse"
android:textSize="16sp"
app:customFont="#string/font_circular_book" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="13dp"
android:layout_marginEnd="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp">
<com.company.app.custom.FontTextView
android:id="#+id/lbl_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="?android:attr/textColorTertiary"
android:textSize="12sp"
app:customFont="#string/font_avenir_medium" />
<ImageView
android:id="#+id/dot1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="14dp"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginStart="14dp"
android:layout_toEndOf="#+id/lbl_time"
android:layout_toRightOf="#+id/lbl_time"
android:scaleType="centerInside"
android:src="#drawable/dot" />
<com.company.app.custom.FontTextView
android:id="#+id/lbl_views"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/dot1"
android:layout_toRightOf="#+id/dot1"
android:textColor="?android:attr/textColorTertiary"
android:textSize="12sp"
app:customFont="#string/font_avenir_medium" />
<ImageView
android:id="#+id/dot2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="14dp"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginStart="14dp"
android:layout_toEndOf="#+id/lbl_views"
android:layout_toRightOf="#+id/lbl_views"
android:scaleType="centerInside"
android:src="#drawable/dot" />
<com.company.app.custom.FontTextView
android:id="#+id/lbl_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/dot2"
android:layout_toRightOf="#+id/dot2"
android:textColor="#color/colorAccent"
android:textSize="12sp"
app:customFont="#string/font_avenir_medium" />
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>

Content layout xml double heigth size inside a NestedScrollView

I have a Coordinator layout in activity xml and an include layout that have a content layout xml. Like this:
<android.support.design.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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:id="#+id/main">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="#layout/content_sign_in" />
</android.support.v4.widget.NestedScrollView>
When i put my content layout inside a nestedscrollview my content layout double your heigth. Anyone can help me?
My Content layout xml:
<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:id="#+id/content_sign_in"
android:layout_width="match_parent"
android:background="#drawable/sign_up_bg"
android:layout_height="match_parent"
tools:showIn="#layout/activity_sign_in">
<ImageButton
android:id="#+id/arrow_back"
android:layout_marginTop="15dp"
android:layout_marginLeft="10dp"
android:scaleType="centerInside"
android:padding="5dp"
android:src="#drawable/ic_back_white"
android:background="#android:color/transparent"
android:layout_width="40dp"
android:layout_height="40dp" />
<ImageView
android:scaleType="centerInside"
android:layout_below="#+id/arrow_back"
android:id="#+id/logo"
android:layout_marginTop="6dp"
android:layout_centerHorizontal="true"
android:layout_width="78dp"
android:layout_height="45dp" />
<android.support.design.widget.TextInputLayout
android:textColorHint="#color/color_80ffffff"
android:id="#+id/input_layout_email"
android:layout_marginLeft="46dp"
android:hint=" "
android:layout_marginRight="46dp"
android:layout_marginTop="74dp"
android:layout_below="#+id/logo"
app:errorTextAppearance="#style/error_appearance"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/work_email"
android:gravity="center"
android:theme="#style/EditTextLogin"
android:textColorHint="#color/color_80ffffff"
android:hint="#string/hint_work_email"
android:textColor="#android:color/white"
android:textSize="14sp"
android:inputType="textEmailAddress"
android:imeOptions="actionNext"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:textColorHint="#color/color_80ffffff"
android:id="#+id/input_layout_password"
android:layout_marginLeft="46dp"
android:hint=" "
android:theme="#style/EditTextLogin"
android:layout_marginRight="46dp"
android:layout_below="#+id/input_layout_email"
app:errorTextAppearance="#style/error_appearance"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/password"
android:gravity="center"
android:textColorHint="#color/color_80ffffff"
android:hint="#string/hint_password"
android:textColor="#android:color/white"
android:textSize="14sp"
android:inputType="textPassword"
android:imeOptions="actionDone"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
<Button
android:layout_below="#+id/input_layout_password"
android:id="#+id/btn_sign_in"
android:textColor="#android:color/white"
android:text="#string/btn_login"
android:layout_marginTop="26dp"
android:background="#color/colorAccent"
android:layout_marginRight="60dp"
android:layout_marginLeft="60dp"
android:layout_width="match_parent"
android:layout_height="40dp" />
<RelativeLayout
android:layout_marginTop="17dp"
android:layout_below="#+id/btn_sign_in"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/label_sign_up"
android:textSize="14sp"
android:text="#string/lbl_sign_up"
android:textColor="#color/color_80ffffff"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_toRightOf="#+id/label_sign_up"
android:textStyle="bold"
android:layout_marginLeft="5dp"
android:id="#+id/btn_sign_up"
android:textSize="14sp"
android:text="#string/txt_sign_up"
android:textColor="#android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<TextView
android:id="#+id/forgot_password"
android:textColor="#color/color_80ffffff"
android:textSize="14sp"
android:gravity="center"
android:text="#string/text_forgot_password"
android:layout_marginBottom="20dp"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout
android:visibility="gone"
android:id="#+id/layout_resend"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="86dp">
<ImageView
android:scaleType="fitXY"
android:src="#drawable/pink_bar"
android:layout_width="match_parent"
android:layout_height="86dp" />
<Button
android:id="#+id/btn_resend"
android:layout_marginRight="10dp"
android:layout_alignParentRight="true"
android:layout_marginTop="26dp"
android:textSize="14sp"
android:text="#string/txt_resend"
android:textColor="#color/color_505065"
android:background="#android:color/transparent"
android:layout_width="wrap_content"
android:layout_height="40dp" />
<ImageView
android:id="#+id/ic_email"
android:layout_marginLeft="16dp"
android:layout_marginTop="26dp"
android:src="#drawable/ic_email_confirmation_white"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_marginLeft="15dp"
android:layout_toRightOf="#+id/ic_email"
android:layout_toLeftOf="#+id/btn_resend"
android:layout_marginTop="26dp"
android:textSize="14sp"
android:text="#string/text_resend_email"
android:textColor="#android:color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
<RelativeLayout
android:visibility="gone"
android:id="#+id/load"
android:background="#aa000000"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_width="50dp"
android:layout_height="50dp" />
</RelativeLayout>
i don't know why this happen
I don't see anything wrong with your layout hierarchy. Things might be a little weird because you are using an image as a background, and no fixed height and width. I don't know if this is a XML background or a image file, but if it is the latter, I'd recommend using an image view inside the relative layout with a fixed size and a scale type defined.

RecyclerView adds marginBottom to its item

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.)

Picture not aligning top?

So in my program i have a layout implemented in which i want the image to alignTop of the parent. I used to exact same layout code for another activity (with minor changes) and it works perfectly but when using it in this activity it does not. My image still aligns to the center fo the view. Here is the layout xml
<?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:background="#color/darkGray"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.intellidev.fuzionvapor.HomeDetails"
tools:showIn="#layout/activity_home_details">
<ImageView
android:id="#+id/homeDetailsActivityImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:scaleType="fitCenter" />
<TextView
android:id="#+id/homeDetailsActivityTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/homeDetailsActivityImage"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/homeDetailsActivityPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/homeDetailsActivityImage"
android:textColor="#color/fuzionRed"
android:textSize="20sp"
android:textStyle="bold" />
<View
android:id="#+id/homeDetailsActivityRuler"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_below="#+id/homeDetailsActivityTitle"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#color/white" />
<TextView
android:id="#+id/homeDetailsActivityDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/homeDetailsActivityRuler"
android:textColor="#color/white"
android:textSize="15sp" />
<LinearLayout
android:id="#+id/homeDetailsFooter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/homeDetailsActivityButton"
android:layout_centerHorizontal="true"
android:orientation="horizontal">
<fr.ganfra.materialspinner.MaterialSpinner
android:id="#+id/homeDetailsActivitySizeSpinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="1dp"
android:layout_weight="1"
app:ms_arrowColor="#color/fuzionRed"
app:ms_arrowSize="16dp"
app:ms_baseColor="#color/fuzionRed"
app:ms_enableFloatingLabel="true"
app:ms_floatingLabelColor="#color/fuzionRed"
app:ms_floatingLabelText="#string/sizeFloatingLabel"
app:ms_highlightColor="#color/fuzionRed"
app:ms_hintColor="#color/fuzionRed"
app:ms_hint="Size"
app:ms_multiline="false"
app:ms_thickness="1dp" />
<fr.ganfra.materialspinner.MaterialSpinner
android:id="#+id/homeDetailsActivityNicotineSpinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:layout_weight="1"
app:ms_arrowColor="#color/fuzionRed"
app:ms_arrowSize="16dp"
app:ms_baseColor="#color/fuzionRed"
app:ms_enableFloatingLabel="true"
app:ms_floatingLabelColor="#color/fuzionRed"
app:ms_floatingLabelText="#string/nicotineFloatingLabel"
app:ms_highlightColor="#color/fuzionRed"
app:ms_hintColor="#color/fuzionRed"
app:ms_multiline="false"
app:ms_hint="Nicotine"
app:ms_thickness="1dp" />
</LinearLayout>
<Button
android:id="#+id/homeDetailsActivityButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="#color/fuzionRed"
android:text="Add To Cart"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="25sp"
android:textStyle="bold" />
</RelativeLayout>
change
<ImageView
android:id="#+id/homeDetailsActivityImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:scaleType="fitCenter" />
to
<ImageView
android:id="#+id/homeDetailsActivityImage"
android:layout_width="match_parent"
android:layout_alignParentTop="true"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:adjustViewBounds="true"
android:scaleType="fitStart" />

Using a CheckBox which doesn't exist in current layout

In my application i have a class named ChatActivity. Actually it is showing a ListView. In onCreate i have set the layout like
super.onCreate(savedInstanceState);
setContentView(R.layout.conversation_window);
conversation_window.xml looks like this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:divider="#null"
android:padding="16dp"
android:fitsSystemWindows="true">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#null"
android:id="#+id/thread_listView"
android:layout_below="#+id/editText"
android:layout_weight="1" />
<View
android:id="#+id/innerLine"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="5dp"
android:background="#9E9E9E"
android:layout_weight="0"
android:layout_marginBottom="12dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="bold"
android:textColor="#212121"
android:layout_marginBottom="8dp"
android:text="(1) 0/158"
android:id="#+id/character_count_textview"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="0"
android:layout_marginBottom="10dp">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/compose_editText"
android:layout_weight="1"
android:layout_marginRight="5dp"
android:hint="এখানে লিখুন..."
android:inputType="textMultiLine|textCapSentences"
android:scrollbars="vertical"
android:background="#drawable/apptheme_textfield_disabled_holo_light"
/>
<ImageButton
android:layout_width="50dp"
android:layout_height="wrap_content"
android:id="#+id/send_imageButton"
android:background="#mipmap/send_black"
/>
</LinearLayout>
For each row of listView there is another xml called list_item_chat_message.xml which looks like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<CheckBox
android:id="#+id/CheckBox_conversation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="20dp"
android:visibility="gone" />
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="10dp"
android:orientation="vertical">
<LinearLayout
android:id="#+id/contentWithBackground"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="#drawable/in_message_bg"
android:orientation="vertical">
<TextView
android:id="#+id/txtMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="200dp"
android:textColor="#android:color/black"
android:textSize="16sp" />
</LinearLayout>
<TextView
android:id="#+id/timeInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:padding="3dp"
android:textColor="#android:color/darker_gray" />
</LinearLayout>
There is a CheckBox in list_item_chat_message.xml which i want to use in my ChatActivity class for setOnCheckedChangeListener.But when i am writing like this in ChatActivity class
itemCheckBox = (CheckBox) findViewById(R.id.CheckBox_conversation);
it throws null object reference. So how i can i declare this CheckBox in this activity?

Categories

Resources