I have a screen requirement like this:
But I cannot get it to work like that. I ended up making a View like this:
I am using a CardView. The List content is dynamically expanding.
<?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.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lblProductName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="19dp"
android:padding="10dp"
android:text="Product Name"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/lblProductQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="19dp"
android:padding="10dp"
android:text="99"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
How can I make my screen to look the same as the required screen?
Try like below code in xml , put your ListView inside CardView;
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:background="#color/color"
android:id="#+id/cv1"
card_view:cardElevation="3.5dp"
card_view:cardBackgroundColor="#fff"
card_view:cardCornerRadius="3dp"
android:foreground="?android:attr/selectableItemBackground"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView
android:id="#+id/study_level_list"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</android.support.v7.widget.CardView>
Add Your Recyclerview inside card view
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/cv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#color/color"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardBackgroundColor="#fff"
card_view:cardCornerRadius="3dp"
card_view:cardElevation="3.5dp">
<android.support.v7.widget.RecyclerView
android:id="#+id/recylerView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</android.support.v7.widget.CardView>
and change your adapter layout as follows
<?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">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lblProductName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="19dp"
android:padding="10dp"
android:text="Product Name"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/lblProductQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="19dp"
android:padding="10dp"
android:text="99"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</RelativeLayout>
Put your List View inside Card View
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_margin="5dp"
card_view:cardCornerRadius="2dp"
card_view:contentPadding="10dp">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</android.support.v7.widget.CardView>
Related
I want to create a layout based on the following image,
as it is evidence I have a CardView that I show it with red lines and the card view is in a LinearLayout and I have an image in the card view in which I want to show a little bit of it in a linear layout.
I use the following code to create the layout,
<?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"
xmlns:card_view="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/grayBack"
android:orientation="vertical"
tools:context=".activities_v2.customer_steps.CustomerStepOne">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/md_white_1000"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginEnd="#dimen/_10sdp"
android:layout_marginRight="#dimen/_10sdp"
android:textColor="#color/editText"
android:textSize="#dimen/_14ssp"
/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_20sdp"
android:layout_marginLeft="#dimen/_20sdp"
android:layout_marginTop="#dimen/_100sdp"
android:layout_marginEnd="#dimen/_20sdp"
android:layout_marginRight="#dimen/_20sdp"
android:layout_marginBottom="#dimen/_10sdp"
android:minHeight="#dimen/_50sdp"
card_view:cardCornerRadius="#dimen/_10sdp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="236dp"
android:layout_height="#dimen/_150sdp"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:src="#drawable/ic_illustration_02" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="#dimen/_10sdp"
android:textColor="#color/editText"
android:textSize="#dimen/_14ssp" />
</LinearLayout>
</android.support.v7.widget.CardView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/button_background_blue"
android:minWidth="#dimen/_150sdp"
android:textSize="#dimen/_14ssp" />
</LinearLayout>
I've got some TextView in a CardView, but when i try to set my TextView "text_lieu" below the TextView "text_nom", nothing happened they are confused. Can you help me please ? <3
Here my xml :
<?xml version="1.0" encoding="utf-8"?>
<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_height="wrap_content"
android:layout_width="match_parent"
card_view:cardCornerRadius="10dp"
android:orientation="vertical"
card_view:cardElevation="10dp"
android:layout_margin="10dp">
<TextView
android:id="#+id/text_nom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_gravity="start"
android:padding="20dp" />
<TextView
android:id="#+id/text_heure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:padding="20dp" />
<TextView
android:id="#+id/text_lieu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp"
android:layout_below="#+id/text_nom"/>
</android.support.v7.widget.CardView>
A CardView extends a FrameLayout basically. That means that views are placed on top of each other, not in a linear fashion like in a LinearLayout. To do this you want to put your TextViews in a LinearLayout inside the CardView:
<?xml version="1.0" encoding="utf-8"?>
<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_height="wrap_content"
android:layout_width="match_parent"
card_view:cardCornerRadius="10dp"
android:orientation="vertical"
card_view:cardElevation="10dp"
android:layout_margin="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/text_nom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_gravity="start"
android:padding="20dp" />
<TextView
android:id="#+id/text_heure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:padding="20dp" />
<TextView
android:id="#+id/text_lieu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp"
android:layout_below="#+id/text_nom"/>
</LinearLayout>
</android.support.v7.widget.CardView>
Note the orientation vertical in the linear layout.
If you want to keep the FrameLayout style, an item in it has the property android:layout_gravity which you can set to bottom to place an item in the bottom.
android:layout_below is only effective in a RelativeLayout.
You can put your views inside a RelativeLayout like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
card_view:cardCornerRadius="10dp"
card_view:cardElevation="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/text_nom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:padding="20dp"
android:textStyle="bold" />
<TextView
android:id="#+id/text_heure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:padding="20dp" />
<TextView
android:id="#+id/text_lieu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text_nom"
android:padding="20dp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
Edit:
if (myTextView3.getText().toString().trim().isEmpty())
myTextView3.setVisibility(View.GONE);
else
myTextView3.setVisibility(View.VISIBLE);
Wrap the textviews in a LinearLayout. You can adjust them they are are, you dont need to do the layout_below. LinearLayout will take care of that for you.
<?xml version="1.0" encoding="utf-8"?>
<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_height="wrap_content"
android:layout_width="match_parent"
card_view:cardCornerRadius="10dp"
android:orientation="vertical"
card_view:cardElevation="10dp"
android:layout_margin="10dp">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/text_nom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:padding="20dp" />
<TextView
android:id="#+id/text_lieu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp"/>
<TextView
android:id="#+id/text_heure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp" />
</LinearLayout>
</android.support.v7.widget.CardView>
I am trying to create an XML layout for football teams statistics and add who scored the goal for each team on the side of the vertical red view
After some work i created this layout:
This is my layout xml code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:card_view="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="5dp"
app:cardUseCompatPadding="true"
card_view:cardCornerRadius="4dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_centerVertical="true"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start">
<ImageView
android:id="#+id/image_team1"
android:layout_width="50dp"
android:layout_height="50dp"
android:adjustViewBounds="true"
android:src="#drawable/placemahdi"
/>
</LinearLayout>
<LinearLayout
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end">
<ImageView
android:id="#+id/image_team2"
android:layout_width="50dp"
android:layout_height="50dp"
android:adjustViewBounds="true"
android:src="#drawable/placemahdi"/>
</LinearLayout>
<TextView
android:id="#+id/versus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_stadium"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text=":"
android:textSize="25sp" />
<com.github.pavlospt.CircleView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="30dp"
android:id="#+id/point1"
android:layout_height="35dp"
app:cv_titleText="2"
app:cv_titleSize="14sp"
android:layout_marginRight="10dp"
android:layout_toStartOf="#+id/versus"
android:layout_toLeftOf="#+id/versus"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
app:cv_titleColor="#color/white"
app:cv_subtitleText=""
app:cv_strokeColorValue="#color/colorGreen"
app:cv_backgroundColorValue="#color/yellow"
app:cv_fillColor="#color/yellow"
app:cv_fillRadius="0.9"
app:cv_strokeWidthSize="3"/>
<com.github.pavlospt.CircleView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="30dp"
android:id="#+id/point2"
android:layout_height="35dp"
app:cv_titleText="2"
app:cv_titleSize="14sp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_toEndOf="#+id/versus"
android:layout_toRightOf="#+id/versus"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
app:cv_titleColor="#color/white"
app:cv_subtitleText=""
app:cv_strokeColorValue="#color/colorGreen"
app:cv_backgroundColorValue="#color/yellow"
app:cv_fillColor="#color/yellow"
app:cv_fillRadius="0.9"
app:cv_strokeWidthSize="3"/>
<TextView
android:id="#+id/team2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="ahed2"
android:textAlignment="center"
android:textSize="10sp"
android:layout_marginTop="5dp"
android:layout_alignParentBottom="true"
android:layout_alignLeft="#+id/point2"
android:layout_alignStart="#+id/point2" />
<TextView
android:id="#+id/team1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_alignParentBottom="true"
android:text="ahed2"
android:textAlignment="center"
android:textSize="10sp"
android:layout_marginTop="5dp"
android:layout_below="#+id/point1"
android:layout_alignLeft="#+id/point1"
android:layout_alignStart="#+id/point1" />
</RelativeLayout>
<View
android:layout_width="2dp"
android:layout_height="300dp"
android:layout_gravity="center"
android:layout_marginTop="50sp"
android:background="#a40404" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center|bottom"
android:layout_gravity="bottom"
android:textSize="20sp"
/>
</android.support.v7.widget.CardView>
</ScrollView>
</LinearLayout>
And this is my layout inflater where i added a recyclerview:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_post"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
Here is an image i am following :
I just want to add the player who scored the goal with the football icon foreach side of the vertical red line.
Should i create two recyclerview?
Any suggestions please?
If you are using LinearLayout with weight property you can reslove this issue..
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_one"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50"/>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:color/holo_red_dark"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_two"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="49"/>
</LinearLayout>
try this..
and cannot solve problem problem with xml editing:
Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/half_padding"
android:paddingLeft="#dimen/main_padding"
android:paddingRight="#dimen/main_padding"
android:paddingBottom="#dimen/main_padding"
>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="#dimen/half_padding"
android:gravity="center_vertical"
>
<TextView android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#color/news_category_color"
android:id="#+id/newsCategory"
android:singleLine="true"
android:ellipsize="end"
android:paddingLeft="#dimen/main_padding"
android:textSize="12dp"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/news_date_color"
android:id="#+id/newsDate"
android:textSize="12dp"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/news_category_color"
android:singleLine="true"
android:id="#+id/reklama"
android:text="#string/reklama"
android:paddingLeft="#dimen/main_padding"
android:textSize="12dp"
/>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_offline"
android:id="#+id/offlineIcon"
android:layout_marginLeft="#dimen/main_padding"
/>
</LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<FrameLayout android:layout_width="99dp"
android:layout_height="74dp"
android:background="#drawable/gray_stroke"
android:padding="3dp"
>
<View android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/placeholder_small"
/>
<uz.muloqot.daryo.view.DaryoTextView android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="#color/place_holder_bg"
android:textColor="#color/place_holder_text"
android:textSize="24dp"
android:text="#string/app_name"
/>
<uz.muloqot.daryo.view.DaryoWebImageView android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:id="#+id/image"
/>
</FrameLayout>
<uz.muloqot.daryo.view.PTSansTextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/main_padding"
android:textSize="16dp"
android:textColor="#color/post_title_color"
android:id="#+id/newsTitle"
/>
</LinearLayout>
</LinearLayout>
while producing this code I get smth. like this:
however I should get this:
Add your code inside CardView And Add RecyclerView
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardCornerRadius="4dp"
android:elevation="5dp">
Add Your Code HERE
</android.support.v7.widget.CardView>
You should use recyclerview layout ,Check the pic here
I have a RecyclerView that programmatically inflates CardViews. The left side of the card is getting cut off and they are not centered. If you need any more code posted, I would be happy to do so.
Here is some helpful code:
Activity:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".Activity.ClassRoster"
tools:showIn="#layout/activity_class_roster"
android:orientation="vertical"
android:gravity="center">
<android.support.v7.widget.RecyclerView android:id="#+id/roster_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingTop="16dp"
android:clipToPadding="false"
android:scrollbars="vertical"
android:gravity="center"/>
</LinearLayout>
Cards being inflated:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/student_card_linlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/student_card"
android:layout_width="#dimen/student_card_width"
android:layout_height="#dimen/student_card_height"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
card_view:cardUseCompatPadding="true"
card_view:cardPreventCornerOverlap="false"
android:clickable="true"
android:foreground="#drawable/custom_bg"
card_view:cardCornerRadius="#dimen/student_card_radius"
card_view:cardElevation="#dimen/student_card_elevation">
<RelativeLayout android:id="#+id/card_layout"
android:background="#color/a"
android:layout_width="match_parent"
android:layout_height="160dp">
<TextView android:id="#+id/student_name"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:textColor="#android:color/white"
android:text="TS"
android:textSize="#dimen/student_card_text_size"
android:gravity="center"
android:textIsSelectable="false"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<android.support.v7.widget.Toolbar android:id="#+id/card_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="bottom">
<ImageView android:id="#+id/student_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="25dp"
android:layout_marginEnd="5dp"
android:src="#drawable/ic_delete_black_24dp"/>
<ImageView android:id="#+id/student_absent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|start"
android:layout_marginBottom="25dp"
android:src="#drawable/ic_change_history_black_24dp"/>
</android.support.v7.widget.Toolbar>
</android.support.v7.widget.CardView>
</LinearLayout>
To make your text center, change TextView width to match_parent
<RelativeLayout android:id="#+id/card_layout"
>
<TextView android:id="#+id/student_name"
android:layout_width="match_parent" // before it is wrap_content
... />
</RelativeLayout>
Make your bottom center correct
// I organize the flow of your layout from left-to-right
// Before it is right-to-left
<android.support.v7.widget.Toolbar android:id="#+id/card_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="bottom">
<ImageView android:id="#+id/student_absent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|start"
android:layout_marginBottom="25dp"
android:src="#drawable/ic_change_history_black_24dp"/>
<ImageView android:id="#+id/student_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="25dp"
android:src="#drawable/ic_delete_black_24dp"/>
</android.support.v7.widget.Toolbar>
Hope this help
Try to remove the top-level LinearLayout of your item xml like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/student_card"
android:layout_width="#dimen/student_card_width"
android:layout_height="#dimen/student_card_height"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
card_view:cardUseCompatPadding="true"
card_view:cardPreventCornerOverlap="false"
android:clickable="true"
android:foreground="#drawable/custom_bg"
card_view:cardCornerRadius="#dimen/student_card_radius"
card_view:cardElevation="#dimen/student_card_elevation">
<RelativeLayout android:id="#+id/card_layout"
android:background="#color/a"
android:layout_width="match_parent"
android:layout_height="160dp">
<TextView android:id="#+id/student_name"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:textColor="#android:color/white"
android:text="TS"
android:textSize="#dimen/student_card_text_size"
android:gravity="center"
android:textIsSelectable="false"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<android.support.v7.widget.Toolbar android:id="#+id/card_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="bottom">
<ImageView android:id="#+id/student_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="25dp"
android:layout_marginEnd="5dp"
android:src="#drawable/ic_delete_black_24dp"/>
<ImageView android:id="#+id/student_absent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|start"
android:layout_marginBottom="25dp"
android:src="#drawable/ic_change_history_black_24dp"/>
</android.support.v7.widget.Toolbar>
</android.support.v7.widget.CardView>