Setting height of View in Android - android

I have a this layout in my application. The black color bar below the image is a View element. I want this bar height to fill the whole area below the image.
This is my layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="#+id/layoutNote"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="#dimen/_10sdp"
app:cardElevation="#dimen/_5sdp"
android:layout_margin="#dimen/_5sdp"
app:cardBackgroundColor="#C9E9FF"
android:padding="#dimen/_5sdp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.makeramen.roundedimageview.RoundedImageView
android:id="#+id/imgNote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:visibility="gone"
app:riv_corner_radius_top_left="#dimen/_10sdp"
app:riv_corner_radius_top_right="#dimen/_10sdp"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:layout_width="3dp"
android:layout_height="match_parent"
android:minHeight="50dp"
android:layout_gravity="start"
android:id="#+id/colorBar"
android:layout_centerVertical="true"
android:background="#color/grad_23"
android:layout_alignParentStart="true"/>
<TextView
android:id="#+id/tvTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="#dimen/_15ssp"
android:padding="#dimen/_5sdp"
android:layout_toEndOf="#id/colorBar"
android:fontFamily="#font/manrope_bold"
android:textColor="#color/lightGrey"/>
<TextView
android:id="#+id/tvWebLink"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:layout_below="#+id/tvTitle"
android:fontFamily="#font/manrope_bold"
android:paddingBottom="#dimen/_2sdp"
android:paddingStart="#dimen/_5sdp"
android:textColor="#color/ColorGray"
android:textSize="#dimen/_12ssp"
android:visibility="gone"
android:autoLink="web"/>
<TextView
android:id="#+id/tvDesc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="#dimen/_11ssp"
android:layout_below="#id/tvWebLink"
android:paddingStart="#dimen/_10sdp"
android:paddingTop="#dimen/_5sdp"
android:paddingBottom="#dimen/_5sdp"
android:paddingEnd="#dimen/_5sdp"
android:fontFamily="#font/manrope_regular"
android:textColor="#color/ColorText"/>
<TextView
android:id="#+id/tvDateTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="#dimen/_9ssp"
android:paddingStart="#dimen/_10sdp"
android:paddingBottom="#dimen/_5sdp"
android:layout_below="#id/tvDesc"
android:fontFamily="#font/manrope_regular"
android:textColor="#color/ColorText"/>
</RelativeLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
In the View tag, when I set the height to match parent, the whole view becomes invisible while running the application, so I'm using a android:minHeight="50dp"
<View
android:layout_width="3dp"
android:layout_height="match_parent"
android:minHeight="50dp"
android:layout_gravity="start"
android:id="#+id/colorBar"
android:layout_centerVertical="true"
android:background="#color/grad_23"
android:layout_alignParentStart="true"/>
I tried using a LinearLayout with layout_weight="1", which didn't work either. Any idea on how I could solve this?

Related

Toolbar on top with weightSum

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>

Text hides when framelayout is set to some custom background (how to not inherit style from parent)

I have a custom drawable as a background to the root of my framelayout with opacity(alpha) of 0.1. I have a LinearLayout inside which has some TextView. When I set my TextViews to the color of my FrameLayout's color it disappears( with no opacity ). How can I set opacity to my background(FrameLayout) without affecting my textviews(child of Framelayout). I have tried a lot of ways but it always hides the textviews inside.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#drawable/ic_img_bg"
android:alpha="0.1"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/linearlayout"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:text="Not Verified,"
android:textSize="32dp"
android:textStyle="bold"
android:textColor="#color/colorViews"
<!-- colorViews same color as framelayout background color it diappears but why?-->
android:padding="16dp"
android:layout_height="wrap_content">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="16dp"
android:text="Sorry, We couldn't verify the mobile number ">
</TextView>
<LinearLayout
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="#drawable/ic_icon_resentotp"
></ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_marginStart="8dp"
android:text="Resend OTP"
android:layout_gravity="center_horizontal"
android:paddingBottom="16dp"
android:layout_height="wrap_content"></TextView>
</LinearLayout>
<View
android:layout_height="4dp"
android:layout_width="match_parent"
android:background="#color/colorViews"
>
</View>
<LinearLayout
android:layout_width="wrap_content"
android:orientation="horizontal"
android:paddingTop="16dp"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:src="#drawable/ic_icon_changemblno1"
android:layout_height="wrap_content">
</ImageView>
<TextView
android:layout_width="wrap_content"
android:text="Change mobile number"
android:layout_height="wrap_content"></TextView>
</LinearLayout>
</LinearLayout>
</FrameLayout>
Well, If someone is still looking for an answer then I have it over here!!
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent">
<FrameLayout android:layout_width="match_parent"
android:background="#drawable/ic_img_bg"
android:alpha="0.1"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/linearlayout"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:text="Not Verified,"
android:textSize="32dp"
android:textStyle="bold"
android:textColor="#color/colorViews"
android:padding="16dp"
android:layout_height="wrap_content">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="16dp"
android:text="Sorry, We couldn't verify the mobile number ">
</TextView>
<LinearLayout
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="#drawable/ic_icon_resentotp"
></ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_marginStart="8dp"
android:text="Resend OTP"
android:layout_gravity="center_horizontal"
android:paddingBottom="16dp"
android:layout_height="wrap_content"></TextView>
</LinearLayout>
<View
android:layout_height="4dp"
android:layout_width="match_parent"
android:background="#color/colorViews"
>
</View>
<LinearLayout
android:layout_width="wrap_content"
android:orientation="horizontal"
android:paddingTop="16dp"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:src="#drawable/ic_icon_changemblno1"
android:layout_height="wrap_content">
</ImageView>
<TextView
android:layout_width="wrap_content"
android:text="Change mobile number"
android:layout_height="wrap_content"></TextView>
</LinearLayout>

TextView not showing up in Linear Layout

I have three TextViews which I want to place inside a Linear Layout. When I do this, the TextFields disappear on the screen. They reappear if I take them out of the Linear Layout, and put them into the Relative Layout, for example.
Below is the code from my Linear Layout:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ViewSingleClub">
<Button
android:id="#+id/btnViewAllClubs"
android:layout_width="177dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:text="Clubs"
android:textAllCaps="false"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="444dp"
android:layout_marginTop="68dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="4dp"
tools:layout_editor_absoluteY="68dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="350dp"
android:background="#drawable/gradientsbackground"
android:orientation="vertical"
android:visibility="visible">
<ImageView
android:id="#+id/imgView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
tools:layout_editor_absoluteX="4dp"
tools:layout_editor_absoluteY="68dp" />
<TextView
android:id="#+id/txtClubName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Club Name"
android:textColor="#fff"
android:textSize="36sp"
android:textStyle="bold"
tools:layout_editor_absoluteX="4dp"
tools:layout_editor_absoluteY="68dp" />
<TextView
android:id="#+id/txtClubDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:text="Club Description"
android:textColor="#color/common_google_signin_btn_text_dark_focused"
android:textSize="30sp"
tools:layout_editor_absoluteX="4dp"
tools:layout_editor_absoluteY="117dp" />
<TextView
android:id="#+id/txtClubEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Email"
android:textColor="#color/common_google_signin_btn_text_dark_focused"
android:textSize="24sp"
tools:layout_editor_absoluteX="4dp"
tools:layout_editor_absoluteY="157dp" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
I don't understand why this is happening. Could anyone help me out?
In your LinearLayout, the layout height is restricted to 350dp, and you have an ImageView with match parent in the layout. Try to make the LinearLayout height to wrap_content, or set a fixed height for the ImageView.
...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="350dp"
android:background="#drawable/bg_gradient"
android:orientation="vertical"
android:visibility="visible">
<ImageView
android:id="#+id/imgView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
tools:layout_editor_absoluteX="4dp"
tools:layout_editor_absoluteY="68dp" />
...
OR
...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg_gradient"
android:orientation="vertical"
android:visibility="visible">
<ImageView
android:id="#+id/imgView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
tools:layout_editor_absoluteX="4dp"
tools:layout_editor_absoluteY="68dp" />
...

Linearlayout above Relativelayout ( gravity bottom )

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>

android:cardView width is not matching to it's parent

Please Read Full - Well I don't know what's gone wrong here.
Each of the CardView Bottom is not matching to it's parent.!
I'm trying to add background to RecyclerView and make transparent background to CardView
custom_row Code -
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardCornerRadius="#dimen/card_album_radius">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingBottom="7.5dp"
android:paddingTop="7.5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp">
<com.makeramen.roundedimageview.RoundedImageView
android:id="#+id/imageView1"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:src="#drawable/ic_action_movie" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:layout_weight="0.75"
android:orientation="vertical">
<TextView
android:id="#+id/playList_name"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="16dp"
android:ellipsize="end"
android:maxLines="1"
android:text="SongName"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Title"
android:textColor="#c1c1c1"
android:textSize="16sp" />
<TextView
android:id="#+id/album_artist"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_below="#id/playList_name"
android:layout_marginLeft="16dp"
android:layout_weight="0.25"
android:ellipsize="end"
android:maxLines="1"
android:text="ARTIST"
android:textColor="#a1a1a1"
android:textIsSelectable="false"
android:textSize="12sp" />
</LinearLayout>
<ImageView
android:id="#+id/my_overflow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_weight="1.4"
android:paddingRight="16dp"
android:scaleType="fitEnd"
android:src="#drawable/ic_grade" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView></LinearLayout>
And here's song_fragment.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.example.ansh.albums.Fragments.Songs">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
Here's the Result which i got -
image
I don't know why each of the cardView is not matching to it's parent width at bottom?
Please help.!
You can use try this to get ride of the bottom divider
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cv"
card_view:cardElevation="0dp"
card_view:cardMaxElevation="0dp"
card_view:cardPreventCornerOverlap="false">

Categories

Resources