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"
Related
I have a view with a title bar above (RelativeLayout) and below a LinearLayout with weightSum.
I used the weightSum because I wanted to distribute the three elements (ImageView, TextView, Button ) 100% contained in the page.
Everything works fine, but when I go to write something from the textview the keyboard appears and the bar disappears from the view because it drags over.
I tried various systems to try to insert the scoolview and keep the bar fixed at the top.
I used both the scrollview and the NestedScrollView and I also changed the bar created with the RelativeLayout to a toolbar.
but the content of the LinearLayout with the weightSum stretches a lot.
do you have any suggestion for me?
thank you
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/fond"
android:fillViewport="true"
tools:context=".client.FicheClient">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_gravity="center|top"
android:gravity="center|top">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#color/surface_l"
android:orientation="horizontal"
android:paddingLeft="56dp"
android:paddingRight="56dp">
<TextView
android:id="#+id/txtNomFichier"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:ellipsize="end"
android:fontFamily="#font/inter_bold_700t"
android:gravity="center_horizontal"
android:maxLines="1"
android:text="#string/label_document"
android:textColor="#color/white"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="backList"
android:paddingStart="16dp"
android:paddingTop="12dp"
android:paddingEnd="16dp"
android:paddingBottom="12dp">
<ImageView
android:id="#+id/btn_Back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/icone_arrow_left_blanc" />
</LinearLayout>
<Button
android:id="#+id/btn_share"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentEnd="true"
android:layout_marginTop="12dp"
android:layout_marginEnd="16dp"
android:background="#drawable/fond_partage"
android:fontFamily="#font/inter_regular_400t"
android:onClick="launchPartage"
android:text=""
android:textColor="#color/blanc"
android:visibility="invisible" />
<ProgressBar
android:id="#+id/progressBarTop"
style="?android:attr/progressBarStyle"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentEnd="true"
android:layout_marginTop="12dp"
android:layout_marginEnd="16dp"
android:theme="#style/colorProgressBarTop" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100">
<LinearLayout
android:layout_margin="16dp"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="77"
android:background="#drawable/radius_gris"
android:orientation="vertical">
<ImageView
android:layout_gravity="center_horizontal|center_vertical"
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.github.barteksc.pdfviewer.PDFView
android:layout_gravity="center_horizontal|center_vertical"
android:id="#+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:layout_weight="11"
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"
android:layout_marginBottom="16dp"
android:padding="12sp"
android:background="#drawable/radius_blanc"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="#+id/txtLibelleNomFichier"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/inter_regular_400t"
android:gravity="left|center_vertical"
android:text="#string/label_file_name_obligatoire"
android:textColor="#color/surface_h"
android:textSize="12sp" />
<EditText
android:id="#+id/txtNom"
android:layout_width="match_parent"
android:layout_height="18dp"
android:background="#drawable/textedit_blanc_rounded_corners"
android:textColor="#color/surface_k"
android:ellipsize="end"
android:textSize="12sp"
android:fontFamily="#font/inter_semi_bold_600t"
android:gravity="left|center_vertical"
android:inputType="text"
android:maxLines="1"
android:layout_marginTop="2dp"
android:scrollHorizontally="true" />
</LinearLayout>
<LinearLayout
android:background="#color/blanc"
android:layout_weight="12"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:orientation="vertical">
<Button
android:id="#+id/btn_upload"
android:layout_width="match_parent"
android:layout_height="39dp"
android:layout_columnWeight="1"
android:layout_margin="16dp"
android:textAllCaps="false"
android:background="#drawable/radius_primary_5"
android:text="#string/btn_validate"
android:textColor="#color/blanc" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
I have created a recyclerview adapter class, with an item layout which contains a cardview inside which there are some textviews and imageviews. The problem I am facing is that when the views are recycled, my cardview size changes and it hides the content of another cardview.
I think the issue is because I have different card heights for each item. So when an item is recycled, it takes the height of another card which is different. How to fix this? Please help..
Video link of the problem: https://drive.google.com/file/d/1nlgq-eQ-rhRNadOyzg4FwjVzrIk88Ve8/view?usp=sharing
open_up_list_view.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="wrap_content">
<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="wrap_content">
<android.support.v7.widget.CardView
android:id="#+id/openUpCardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/nav_header_vertical_spacing"
android:layout_marginEnd="#dimen/dimen_16x"
android:layout_marginLeft="#dimen/activity_vertical_margin"
android:layout_marginRight="#dimen/dimen_16x"
android:layout_marginStart="#dimen/activity_vertical_margin"
android:layout_marginTop="#dimen/dimen_4x"
android:clickable="true"
android:focusable="true"
app:cardCornerRadius="#dimen/dimen_8x">
<RelativeLayout
android:id="#+id/openUpRelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="#dimen/dimen_8x"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:id="#+id/openUpAuthorImageProgress"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/openUpAuthorImage"
android:layout_width="#dimen/dimen_48x"
android:layout_height="#dimen/dimen_48x"
android:layout_marginBottom="#dimen/dimen_4x"
android:layout_marginLeft="#dimen/dimen_4x"
android:layout_marginRight="#dimen/dimen_4x"
android:layout_marginTop="#dimen/dimen_4x"
app:civ_border_color="#FF000000"
app:civ_border_width="2dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/openUpAuthorName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/cardview_default_radius"
android:layout_marginLeft="#dimen/dimen_8x"
android:layout_marginRight="#dimen/dimen_8x"
android:layout_marginTop="#dimen/dimen_8x"
android:text="loading.."
android:textColor="#color/colorPrimaryDark"
android:textSize="#dimen/dimen_16x"
android:textStyle="bold" />
<TextView
android:id="#+id/openUpDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/openUpAuthorName"
android:layout_marginLeft="#dimen/dimen_8x"
android:textSize="#dimen/dimen_12x" />
</RelativeLayout>
</LinearLayout>
<TextView
android:id="#+id/openUpTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="left"
android:autoLink="web"
android:padding="#dimen/dimen_4x"
android:textAlignment="textStart"
android:textColor="#color/cardview_dark_background"
android:textSize="#dimen/dimen_16x" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="#+id/openUpImageProgress"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.github.chrisbanes.photoview.PhotoView
android:id="#+id/openUpImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/dimen_8x"
android:layout_marginLeft="#dimen/dimen_4x"
android:layout_marginRight="#dimen/dimen_4x"
android:layout_marginTop="#dimen/dimen_8x"
android:layout_weight="1"
app:srcCompat="#drawable/common_google_signin_btn_icon_dark" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#android:color/darker_gray"
android:hapticFeedbackEnabled="false"></View>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<CheckBox
android:id="#+id/openUpLikeIcon"
android:layout_width="#dimen/dimen_32x"
android:layout_height="#dimen/dimen_24x"
android:layout_marginBottom="#dimen/dimen_4x"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:background="#drawable/thumb_off"
android:button="#null"
android:checked="false"
android:clickable="true"
android:focusable="true"
android:stateListAnimator="#animator/scale"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/image" />
<TextView
android:id="#+id/openUpLikeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/nav_header_vertical_spacing"
android:layout_marginTop="#dimen/dimen_8x"
android:text="loading.."
android:textSize="#dimen/dimen_16x" />
<ImageView
android:id="#+id/openUpCommentIcon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/fab_margin"
android:layout_marginTop="#dimen/dimen_8x"
app:srcCompat="#drawable/comment_icon" />
<TextView
android:id="#+id/openUpCommentTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dimen_8x"
android:text="loading.."
android:textSize="#dimen/dimen_16x" />
<TextView
android:id="#+id/openUpDeleteText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/dimen_4x"
android:layout_marginTop="#dimen/dimen_8x"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="Delete"
android:textSize="#dimen/dimen_16x" />
</LinearLayout>
<View
android:id="#+id/commentSeparatorView"
android:layout_width="match_parent"
android:layout_height="1.5dp"
android:layout_marginTop="#dimen/nav_header_vertical_spacing"
android:background="#color/colorPrimaryDark"
android:hapticFeedbackEnabled="false"></View>
<TextView
android:id="#+id/commentSeparatorText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="#dimen/dimen_8x"
android:gravity="center"
android:text="Comments"
android:textColor="#color/common_google_signin_btn_text_dark_focused" />
<LinearLayout
android:id="#+id/commentsLL"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/dimen_4x"
android:background="#null"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/commentsRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Add a comment..">
<android.support.design.widget.TextInputEditText
android:id="#+id/commentEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
<android.support.v7.widget.AppCompatButton
android:id="#+id/commentPostButton"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:backgroundTint="#color/colorPrimaryDark"
android:text="POST"
android:textColor="#color/cardview_light_background" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
</ScrollView>
EDIT: RecyclerView layout
fragment_open_up.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.bittentech.localvariable.fragments.OpenUpFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:id="#+id/openUpEmptyView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center_vertical|center_horizontal"
android:text="All caught up!!" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/openUpSwipeRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/openUpRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false"/>
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
I want to build the following screen which contains app logo, success/failure icon image, information message and ok button.
Here this the code. I am using linear layout to achieve this.
<LinearLayout
android:id="#+id/statusLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="#android:color/white"
android:weightSum="2"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:id="#+id/statusTopRelativeLayout"
android:background="#android:color/holo_blue_bright"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="1">
<ImageView
android:id="#+id/client_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/no_image_description"
android:src="#drawable/client_logo"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/statusBottomRelativeLayout"
android:background="#android:color/holo_blue_light"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="#+id/statusText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:text="#string/statusText"
android:textSize="50sp"/>
<Button
android:id="#+id/btnOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/statusText"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:clickable="true"
android:focusable="true"
android:onClick="goToHomeScreen"
android:paddingBottom="15dp"
android:paddingTop="15dp"
android:text="#string/ok"
android:textColor="#ffffff"
android:textSize="40sp"/>
</RelativeLayout>
How to place success/failure icon image on top of the two layouts?
You can use constraint to make it easy
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.constraint.Guideline
android:id="#+id/center"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="#id/center"
android:background="#ffffff"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="#id/center"
app:layout_constraintBottom_toBottomOf="parent"
android:background="#00ffff"/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#ff8801"
app:layout_constraintTop_toTopOf="#id/center"
app:layout_constraintBottom_toBottomOf="#id/center"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout>
Output:
Try this
<?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"
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="vertical">
<LinearLayout
android:id="#+id/nilu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/colorPrimary"
android:orientation="vertical"
android:paddingBottom="30dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
</LinearLayout>
<LinearLayout
android:id="#+id/nilu2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/nilu"
android:layout_weight="1"
android:background="#color/colorAccent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#mipmap/ic_launcher_round" />
</RelativeLayout>
</RelativeLayout>
OUTPUT
Parent RelativeLayout
add child LinearLayout as fillParent and assign weightsum 2. add two
layouts with 1 weight each. (add individual implementation for each
layout according to your requirements.)
add second child in relative
layout as imageview/button for that good sign and set it center in
parent.
This will fix your problem
The TextViews used in the following layout do not get wrapped in the screen and go out on the left (or start) edge of the screen.
<?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"
android:layout_width="match_parent" android:layout_height="match_parent"
>
<LinearLayout
android:id="#+id/text_pane"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/iv_video_thumbnail"
android:layout_toStartOf="#+id/iv_video_thumbnail"
android:orientation="vertical">
<TextView
android:id="#+id/tv_video_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_gravity="end"
android:padding="#dimen/text_padding"/>
<TextView
android:padding="#dimen/text_padding"
android:layout_gravity="end"
android:id="#+id/tv_video_descr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
<ImageView
android:id="#+id/iv_video_thumbnail"
android:layout_width="#dimen/thumbnail_width"
android:layout_height="#dimen/thumbnail_height"
android:layout_alignBottom="#+id/text_pane"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:contentDescription="#string/video_thumbnail_image"
app:srcCompat="#drawable/video" />
</RelativeLayout>
I do not know why the text goes out of screen on the left side. I have tried using margin and padding for the RelativeLayout and LinearLayout and the two TextViews, but none of them solved the problem.
Currently, the app displays content as follows:
As you see in the code, I have also applied the gravity attribute to the TextViews, but no success yet. Does anyone know how to solve this?
Try this!!
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tv_video_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:padding="10dp"
android:text="#android:string/dialog_alert_title"
app:layout_constraintEnd_toStartOf="#+id/iv_video_thumbnail"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/tv_video_descr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:padding="10dp"
android:text="#android:string/fingerprint_icon_content_description"
app:layout_constraintEnd_toStartOf="#+id/iv_video_thumbnail"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tv_video_title" />
<ImageView
android:id="#+id/iv_video_thumbnail"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginBottom="1dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="#+id/tv_video_descr"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/your_img" />
</android.support.constraint.ConstraintLayout>
Try this...
<?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:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/text_pane"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_toLeftOf="#+id/iv_video_thumbnail"
android:layout_toStartOf="#+id/iv_video_thumbnail"
android:layout_weight=".2"
android:orientation="vertical">
<TextView
android:id="#+id/tv_video_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:gravity="right"
android:layout_margin="3dp"
android:layout_weight=".1"
android:padding="10dp"/>
<TextView
android:padding="10dp"
android:id="#+id/tv_video_descr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_weight=".3"
android:text="" />
</LinearLayout>
<ImageView
android:id="#+id/iv_video_thumbnail"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_alignBottom="#+id/text_pane"
android:layout_alignParentEnd="true"
android:layout_weight=".1"
android:scaleType="fitXY"
android:layout_alignParentRight="true"/>
</LinearLayout>
Output:
Use this layout instead.
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/text_pane"
android:layout_width="0dp"
android:padding="#dimen/text_padding"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:orientation="vertical">
<TextView
android:id="#+id/tv_video_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="Hi" />
<TextView
android:id="#+id/tv_video_descr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="Hi" />
</LinearLayout>
<ImageView
android:id="#+id/iv_video_thumbnail"
android:layout_width="0dp"
android:layout_height="#dimen/thumbnail_height"
android:layout_alignBottom="#+id/text_pane"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_weight="0.3"
app:srcCompat="#drawable/video" />
</LinearLayout>
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>