I have to create three CardView like structure as shown in the below image. For that, I am currently using
Constraintlayout but facing multiple issues i.e, clipping issue.
There is no usecase of swipe animation or anything like that.
Is there anything that I am missing here.Any help will be appreciated.
Here is my code:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:id="#+id/card_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:rotation="-20"
android:layout_marginTop="#dimen/dimen_12"
android:layout_marginStart="#dimen/dimen_25"
app:cardCornerRadius="#dimen/dimen_8"
app:cardElevation="#dimen/dimen_1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:id="#+id/rl_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/top_colored_gradient_dark"
android:padding="#dimen/dimen_12">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/img_one"
android:layout_width="72dp"
android:layout_height="72dp"
android:src="#drawable/blue_social" />
<TextView
android:id="#+id/txt_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/img_one"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/dimen_15"
android:textColor="#313131"
android:textSize="#dimen/dimen_14sp"
tools:text="Title Here" />
<TextView
android:id="#+id/txt_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txt_name"
android:layout_centerHorizontal="true"
android:textColor="#color/light_text_color"
android:textSize="#dimen/dimen_11sp"
tools:text="Date" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/card_second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardElevation="#dimen/dimen_2"
app:cardUseCompatPadding="true"
app:cardCornerRadius="#dimen/dimen_8"
android:layout_marginEnd="#dimen/dimen_15"
app:layout_constraintEnd_toStartOf="#id/card_third"
app:layout_constraintStart_toEndOf="#id/card_one"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:id="#+id/rl_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/top_colored_gradient_dark"
android:padding="#dimen/dimen_12">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/img_two"
android:layout_width="72dp"
android:layout_height="72dp"
android:src="#drawable/blue_social" />
<TextView
android:id="#+id/txt_name_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/img_two"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/dimen_15"
android:textColor="#313131"
android:textSize="#dimen/dimen_14sp"
tools:text="Title Here" />
<TextView
android:id="#+id/txt_date_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txt_name_two"
android:layout_centerHorizontal="true"
android:textColor="#color/light_text_color"
android:textSize="#dimen/dimen_11sp"
tools:text="Date" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/card_third"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardElevation="#dimen/dimen_1"
app:cardCornerRadius="#dimen/dimen_8"
android:layout_marginTop="#dimen/dimen_8"
android:rotation="20"
app:cardUseCompatPadding="true"
app:layout_constraintStart_toEndOf="#id/card_second"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:id="#+id/rl_third"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/top_colored_gradient_dark"
android:padding="#dimen/dimen_12">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/img_third"
android:layout_width="72dp"
android:layout_height="72dp"
android:src="#drawable/blue_social" />
<TextView
android:id="#+id/txt_name_third"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/img_third"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/dimen_15"
android:textColor="#313131"
android:textSize="#dimen/dimen_14sp"
tools:text="Title Here" />
<TextView
android:id="#+id/txt_date_third"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txt_name_third"
android:layout_centerHorizontal="true"
android:textColor="#color/light_text_color"
android:textSize="#dimen/dimen_11sp"
tools:text="Date" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
You can use FrameLayout instead of constraint to stack Views like in the Image.
Related
Textview fills all the space and leaves no room for the other text view.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/cv_prof"
android:layout_toEndOf="#id/cv_prof"
android:layout_alignParentEnd="true"
android:orientation="horizontal">
<TextView
android:id="#+id/tv_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/bg_other_user_chat"
android:fontFamily="#font/sf_pro_display_light"
android:padding="#dimen/_10sdp"
android:textColor="#color/blue_theme"
android:textSize="#dimen/_11ssp" />
<TextView
android:id="#+id/tv_time_sent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_5sdp"
android:layout_marginEnd="#dimen/_15sdp"
android:fontFamily="#font/sf_pro_display_light"
android:text="#string/placeholder_time"
android:textColor="#color/white"
android:textSize="#dimen/_8ssp" />
</LinearLayout>
How can i achieve this results?
Please help me
Result 1:
Result 2:
You should add layout_weight element into child view of LinearLayout. Ex:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/cv_prof"
android:layout_toEndOf="#id/cv_prof"
android:layout_alignParentEnd="true"
android:orientation="horizontal">
<TextView
android:id="#+id/tv_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/bg_other_user_chat"
android:fontFamily="#font/sf_pro_display_light"
android:padding="#dimen/_10sdp"
android:textColor="#color/blue_theme"
android:textSize="#dimen/_11ssp"
android:layout_weight="1"/>
<TextView
android:id="#+id/tv_time_sent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_5sdp"
android:layout_marginEnd="#dimen/_15sdp"
android:fontFamily="#font/sf_pro_display_light"
android:text="#string/placeholder_time"
android:textColor="#color/white"
android:textSize="#dimen/_8ssp"
android:layout_weight="1"/>
</LinearLayout>
set weight = 1 for 2 TextViews that mean width of them will be the same.
Edit:
If you want to use constrain layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:id="#+id/imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_pdf"
android:padding="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="#id/tv_content"/>
<TextView
android:id="#+id/tv_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:src="#drawable/ic_pdf"
android:text="abcdjhfjdgfgfdgdfgfdgfdg gfdg hgjkdfhgj fdghjkfdhg hgjkfdh sdgdfg fgnjkdfgh fghfdhg fgjk"
app:layout_constraintBottom_toBottomOf="#+id/imageview"
app:layout_constraintEnd_toStartOf="#id/tv_time_sent"
app:layout_constraintStart_toEndOf="#id/imageview"
app:layout_constraintTop_toTopOf="#+id/imageview" />
<TextView
android:id="#+id/tv_time_sent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="10:00pm"
app:layout_constraintBottom_toBottomOf="#+id/imageview"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/tv_content"
app:layout_constraintTop_toTopOf="#+id/imageview" />
</androidx.constraintlayout.widget.ConstraintLayout>
I have such XML file for custom Dialog:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:paddingHorizontal="15dp"
android:paddingVertical="10dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:paddingBottom="15dp">
<TextView
style="#style/tv_big"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="#id/cl_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="Filter"/>
<com.google.android.material.button.MaterialButton
android:id="#+id/bt_reset"
android:textColor="#color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/Widget.MaterialComponents.Button.OutlinedButton"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="#id/cl_header"
android:text="RESET FILTERS"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl_distance"
app:layout_constraintTop_toBottomOf="#id/cl_header"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tv_distance_title"
style="#style/tv_medium"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Distance range"/>
<TextView
android:id="#+id/tv_distance_result"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="#id/tv_distance_title"
app:layout_constraintLeft_toRightOf="#id/tv_distance_title"
app:layout_constraintRight_toRightOf="parent"
android:background="#ddd"
android:padding="3dp"
android:textColor="#333"
android:text="0 km - 500km"/>
<com.google.android.material.slider.RangeSlider
android:id="#+id/slider_distance"
app:layout_constraintTop_toBottomOf="#id/tv_distance_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:labelBehavior="gone"
android:stepSize="1.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl_location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/cl_distance"
app:layout_constraintStart_toStartOf="parent">
<TextView
android:id="#+id/tv_location_title"
style="#style/tv_medium"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Location"/>
<EditText
android:id="#+id/et_location"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:layout_constraintTop_toBottomOf="#id/tv_location_title"
android:hint="#string/filter_location_et_hint" />
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/cl_location"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<Button
android:id="#+id/bt_cancel"
android:backgroundTint="#ccc"
android:textColor="#color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="CANCEL"/>
<Button
android:id="#+id/bt_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="save"
android:layout_marginHorizontal="20dp"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Android Studio renders it in this way:
And this is what I want to have in my Dialog.
BUT:
On physical device and on emulator it looks different than in Android Studio:
My question is: how to place "Filter" title on the left, and make the location EditText matching the parent (in the working app)?
What everybody else said is correct, keeping your layout flat is good for both performance and for these situations where you want to quickly figure out why isn't the layout being laid out the way you wanted it ;)
Try this :
<androidx.constraintlayout.widget.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"
android:paddingHorizontal="15dp"
android:paddingVertical="10dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="start"
android:text="Filter"
app:layout_constraintBottom_toBottomOf="#id/bt_reset"
app:layout_constraintEnd_toStartOf="#id/bt_reset"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#id/bt_reset" />
<com.google.android.material.button.MaterialButton
android:id="#+id/bt_reset"
style="#style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RESET FILTERS"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/tv_distance_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Distance range"
app:layout_constraintBottom_toBottomOf="#id/tv_distance_result"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#id/tv_distance_result" />
<TextView
android:id="#+id/tv_distance_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="#ddd"
android:gravity="center"
android:paddingHorizontal="18dp"
android:paddingVertical="3dp"
android:text="0 km - 500km"
android:textColor="#333"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/bt_reset" />
<com.google.android.material.slider.RangeSlider
android:id="#+id/slider_distance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stepSize="1.0"
app:labelBehavior="gone"
app:layout_constraintTop_toBottomOf="#id/tv_distance_result" />
<TextView
android:id="#+id/tv_location_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Location"
app:layout_constraintTop_toBottomOf="#id/slider_distance" />
<EditText
android:id="#+id/et_location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="test"
app:layout_constraintTop_toBottomOf="#id/tv_location_title" />
<Button
android:id="#+id/bt_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:backgroundTint="#ccc"
android:text="CANCEL"
android:textColor="#color/colorBlack"
app:layout_constraintEnd_toStartOf="#id/bt_save"
app:layout_constraintTop_toBottomOf="#id/et_location" />
<Button
android:id="#+id/bt_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:text="save"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/et_location" />
</androidx.constraintlayout.widget.ConstraintLayout>
I changed inner ConstraintLayouts into LinearLayouts and used weights. I also used this trick to fill space between e.g. "Filter" title and "reset filters" button.
There was also an issue with ll_location LinearLayout - it didn't match the parent.
I replaced:
<LinearLayout
android:id="#+id/ll_location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/ll_distance_ext"
android:orientation="vertical">
<!-- content -->
</LinearLayout>
into:
<LinearLayout
android:id="#+id/ll_location"
android:layout_width="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/ll_distance_ext"
android:orientation="vertical">
<!-- content -->
</LinearLayout>
And then it worked.
The reason why I don't want to use flat layout (why I use nested layouts) is that IMHO the flat layout makes the code more difficult to maintain.
When you have Views splited into groups you can easily replace them, no matter how many View there are in a group.
My solution:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:paddingHorizontal="15dp"
android:paddingVertical="10dp">
<LinearLayout
android:id="#+id/ll_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:paddingBottom="15dp">
<TextView
style="#style/tv_big"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="Filter"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<com.google.android.material.button.MaterialButton
android:id="#+id/bt_reset"
android:textColor="#color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/Widget.MaterialComponents.Button.OutlinedButton"
android:text="reset filters"/>
</LinearLayout>
<LinearLayout
android:id="#+id/ll_distance_ext"
app:layout_constraintTop_toBottomOf="#id/ll_header"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/tv_distance_title"
style="#style/tv_medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Distance range"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:id="#+id/tv_distance_result"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:textAlignment="center"
android:background="#ddd"
android:padding="3dp"
android:textColor="#333"
android:text="0 km - 500km"/>
</LinearLayout>
<com.google.android.material.slider.RangeSlider
android:id="#+id/slider_distance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:labelBehavior="gone"
android:stepSize="1.0" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_location"
android:layout_width="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/ll_distance_ext"
android:orientation="vertical">
<TextView
android:id="#+id/tv_location_title"
style="#style/tv_medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Location"/>
<EditText
android:id="#+id/et_location"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:hint="#string/filter_location_et_hint" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/ll_location"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<Button
android:id="#+id/bt_cancel"
android:backgroundTint="#ccc"
android:textColor="#color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="cancel"/>
<Button
android:id="#+id/bt_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="save"
android:layout_marginHorizontal="20dp"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
I implemented some examples for Shimmer effect for learning. I don't understand that why people are using separate placeholder layout for while using shimmer effect?
Can't we do change color programmatically and do it for the row which we're used in Adapter class?
See the code for my adapter class row:
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 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:clickable="true"
android:focusable="true"
android:foreground="?selectableItemBackground"
app:cardCornerRadius="3dp"
app:cardElevation="5dp"
app:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<LinearLayout
android:id="#+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_toStartOf="#+id/delete"
android:orientation="vertical">
<TextView
android:id="#+id/eventTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:textColor="#color/colorBlack"
android:textSize="18sp"
android:visibility="gone" />
<TextView
android:id="#+id/eventDes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:visibility="gone" />
<TextView
android:id="#+id/eventAttendee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:visibility="gone" />
<TextView
android:id="#+id/eventStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:visibility="gone" />
<TextView
android:id="#+id/eventEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:visibility="gone" />
<TextView
android:id="#+id/eventLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:visibility="gone" />
</LinearLayout>
<ImageView
android:id="#+id/delete"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:clickable="true"
android:focusable="true"
android:tint="#color/colorBlack"
app:srcCompat="#drawable/ic_baseline_delete_24" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
Can I do that with this layout only? or should I create separate? If separate, can you please tell me how to do that for this above row? Everyone using "view" layout only. I don't understand this.
The reason for declaring a new layout is because you have to wrap your views inside Shimmerlayout and its parent layout will be either frame layout or linear layout. So basically you are restricted in terms of which container to use. Moreover, you are only going to show shimmer animation for a few seconds so using it as a primary ViewGroup is not recommended.
So to create this row just wrap it inside
<?xml version="1.0" encoding="utf-8"?>
<com.facebook.shimmer.ShimmerFrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/shimmer_view_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:foreground="?selectableItemBackground"
app:cardCornerRadius="3dp"
app:cardElevation="5dp"
app:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<LinearLayout
android:id="#+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_toStartOf="#+id/delete"
android:orientation="vertical">
<TextView
android:id="#+id/eventTitle"
android:layout_width="wrap_content"
android:layout_height="15dp"
android:layout_marginStart="12dp"
android:textSize="18sp"
android:text="your title"
android:background="#cecece"
android:textColor="#cecece"
/>
<TextView
android:id="#+id/eventDes"
android:layout_width="match_parent"
android:layout_height="15dp"
android:layout_marginStart="12dp"
android:layout_marginTop="8dp"
android:text="your sample description goes here"
android:background="#cecece"
android:textColor="#cecece"
/>
<TextView
android:id="#+id/eventAttendee"
android:layout_width="wrap_content"
android:layout_height="15dp"
android:layout_marginStart="12dp"
android:layout_marginTop="8dp"
android:text="your eventAttendee"
android:background="#cecece"
android:textColor="#cecece"
/>
<TextView
android:id="#+id/eventStart"
android:layout_width="wrap_content"
android:layout_height="15dp"
android:layout_marginStart="12dp"
android:layout_marginTop="8dp"
android:text="your start time"
android:background="#cecece"
android:textColor="#cecece"
/>
<TextView
android:id="#+id/eventEnd"
android:layout_width="wrap_content"
android:layout_height="15dp"
android:layout_marginStart="12dp"
android:layout_marginTop="8dp"
android:text="your end time"
android:background="#cecece"
android:textColor="#cecece"
/>
<TextView
android:id="#+id/eventLocation"
android:layout_width="wrap_content"
android:layout_height="15dp"
android:layout_marginStart="12dp"
android:layout_marginTop="8dp"
android:text="your location"
android:background="#cecece"
android:textColor="#cecece"
/>
</LinearLayout>
<ImageView
android:id="#+id/delete"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:clickable="true"
android:focusable="true"
android:tint="#cecece"
app:srcCompat="#drawable/ic_delete" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
</com.facebook.shimmer.ShimmerFrameLayout>
Now when you have to start it just use -
`
ShimmerFrameLayout container =
(ShimmerFrameLayout) findViewById(R.id.shimmer_view_container);
container.startShimmer();
I have aligned it perfectly in the android studio but when I'm running it, it goes out of order, I have tried in a smartphone as well as in emulator but the result is same.is there any way I can make it display in mobile the same the way I see in the android studio?
The pic that I have uploaded shows that in android studio the display looks perfectly fine but after running its position changes.
this is the xml :
<?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"
android:background="#drawable/wm"
tools:context="sanal.gmail.android.PetCare.doctorassignment">
<ImageView
android:id="#+id/imageView9"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginTop="36dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/petownerde" />
<ImageView
android:id="#+id/imageView11"
android:layout_width="match_parent"
android:layout_height="38dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout6"
app:srcCompat="#drawable/pet" />
<EditText
android:id="#+id/editText10"
android:layout_width="213dp"
android:layout_height="142dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="472dp"
android:background="#drawable/button"
android:ems="10"
android:gravity="top|left"
android:hint="Type your message here"
android:inputType="textMultiLine"
android:lines="10"
android:maxLength="160"
android:maxLines="5"
android:minLines="6"
android:scrollbars="vertical"
android:singleLine="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.036"
tools:layout_editor_absoluteX="99dp" />
<Button
android:id="#+id/button5"
android:layout_width="88dp"
android:layout_height="44dp"
android:layout_marginBottom="60dp"
android:layout_marginEnd="162dp"
android:layout_marginLeft="161dp"
android:layout_marginRight="162dp"
android:layout_marginStart="161dp"
android:layout_marginTop="19dp"
android:background="#drawable/button1"
android:onClick="sendmessage"
android:text="SEND"
android:textColor="#F6F6F6"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/editText10" />
<LinearLayout
android:id="#+id/linearLayout5"
android:layout_width="match_parent"
android:layout_height="168dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView11"
app:layout_constraintVertical_bias="0.049">
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="84dp"
android:layout_height="160dp"
android:orientation="vertical">
<TextView
android:id="#+id/textView21"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:text="Pet name :"
android:textSize="18sp" />
<TextView
android:id="#+id/textView22"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:text="Breed :"
android:textSize="18sp" />
<TextView
android:id="#+id/textView23"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:text="Colour :"
android:textSize="18sp" />
<TextView
android:id="#+id/textView24"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:text="Age :"
android:textSize="18sp" />
<TextView
android:id="#+id/textView25"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Gender :"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="#+id/textView13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pet name"
android:textColor="#F6F6F6"
android:textSize="18sp" />
<TextView
android:id="#+id/textView14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="breed"
android:textColor="#F6F6F6"
android:textSize="18sp" />
<TextView
android:id="#+id/textView15"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="colour"
android:textColor="#F6F6F6"
android:textSize="18sp" />
<TextView
android:id="#+id/textView16"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="age"
android:textColor="#F6F6F6"
android:textSize="18sp" />
<TextView
android:id="#+id/textView17"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="gender"
android:textColor="#F6F6F6"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout6"
android:layout_width="match_parent"
android:layout_height="136dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="31dp"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="#+id/imageView11"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView9">
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="79dp"
android:layout_height="126dp"
android:orientation="vertical">
<TextView
android:id="#+id/textView18"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="Name :"
android:textSize="18sp" />
<TextView
android:id="#+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="Email :"
android:textSize="18sp" />
<TextView
android:id="#+id/textView9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="Contact : "
android:textSize="18sp" />
<TextView
android:id="#+id/textView8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Address : "
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textView7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="name"
android:textColor="#F6F6F6"
android:textSize="18sp" />
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="email "
android:textColor="#F6F6F6"
android:textSize="18sp" />
<TextView
android:id="#+id/textView11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="phone number"
android:textColor="#F6F6F6"
android:textSize="18sp" />
<TextView
android:id="#+id/textView12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="address"
android:textColor="#F6F6F6"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
`
Follow these two links You will get your answer. Its a time consuming approach but definitely you will learn a lot from these links.
http://developer.android.com/training/multiscreen/screensizes.html
http://developer.android.com/guide/practices/screens_support.html
Making fully responsive your android application to all screen sizes is not a very tough job but it requires good knowledge and experience of layouts and there XML properties.
use RelativeLayout instead of constraintLayout
and give the perfectly position of your views they cant change view your layout
use property of RelativeLayout -> below , above , toLeftOf , toRightOf
and set your other component
and also height and width all component not fixed given..
your requirement fixed size then given fixed otherwise use match_parent and wrap_content
one important things for your layout either you can use scrollview coz your edittext and button are mess ... OR your component size given small then not mess your layout
also you can fixed size or density used then use Dependency SDP and SSP
For android there are several ways to make it Compatible with all the devices.
You can use the ConstraintLayout for more responsive activity instead of LinearLayout.
Apart from that use more flexible and adaptive layout like "match_parent", "wrap_content" instead of hard coded values.
For example -
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:margin_top="5sp"
And so on. I hope this will solve your problem.
For more info related to this you can check this link
I was playing around with ConstraintLayout and I can't guess how to do this simple design using only a ConstraintLayout.
Simple design
Each TextView is centered with its image.
Each image is separated with the previous image with a fixed margin.
All views, treated like a group, are centered horizontally.
I have implemented the design using RelativeLayout:
<?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">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="4dp">
<RelativeLayout
android:id="#+id/androidALayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/androidAIV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#mipmap/ic_launcher"
android:layout_centerHorizontal="true"/>
<TextView
android:id="#+id/androidATV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android A"
android:layout_below="#id/androidAIV"
android:layout_marginTop="4dp"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/androidBLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/androidALayout"
android:layout_marginLeft="32dp">
<ImageView
android:id="#+id/androidBIV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#mipmap/ic_launcher"
android:layout_centerHorizontal="true"/>
<TextView
android:id="#+id/androidBTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android B"
android:layout_below="#id/androidBIV"
android:layout_marginTop="4dp"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/androidCLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/androidBLayout"
android:layout_marginLeft="32dp">
<ImageView
android:id="#+id/androidCIV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#mipmap/ic_launcher"
android:layout_centerHorizontal="true"/>
<TextView
android:id="#+id/androidCTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android C"
android:layout_below="#id/androidCIV"
android:layout_marginTop="4dp"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/androidDLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/androidCLayout"
android:layout_marginLeft="32dp">
<ImageView
android:id="#+id/androidDIV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#mipmap/ic_launcher"
android:layout_centerHorizontal="true"/>
<TextView
android:id="#+id/androidDTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android D"
android:layout_below="#id/androidDIV"
android:layout_marginTop="4dp"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
Is this possible?
It surely is possible. The best approach is choosing the first ImageView as reference element to which constrain everything else.
Center the TextView by assigning the left and right constraints to its image left and right edges respectively.
Then assign each image left and top contrain to their right and top edge of the previous image respectively.
Finally select all the images in the layout editor, right click and Center Horizontally (this will chain them to fit the screen width)
Example:
<?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">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintLeft_toLeftOf="#+id/imageView"
app:layout_constraintRight_toRightOf="#+id/imageView"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/imageView" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#mipmap/ic_launcher"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="30dp"
app:layout_constraintRight_toLeftOf="#+id/imageView2" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintLeft_toLeftOf="#+id/imageView2"
app:layout_constraintRight_toRightOf="#+id/imageView2"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/imageView2" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#mipmap/ic_launcher"
app:layout_constraintLeft_toRightOf="#+id/imageView"
app:layout_constraintTop_toTopOf="#+id/imageView"
app:layout_constraintRight_toLeftOf="#+id/imageView3" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintLeft_toLeftOf="#+id/imageView3"
app:layout_constraintRight_toRightOf="#+id/imageView3"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/imageView3" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#mipmap/ic_launcher"
app:layout_constraintLeft_toRightOf="#+id/imageView2"
app:layout_constraintTop_toTopOf="#+id/imageView2"
app:layout_constraintRight_toLeftOf="#+id/imageView4" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintLeft_toLeftOf="#+id/imageView4"
app:layout_constraintRight_toRightOf="#+id/imageView4"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/imageView4" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#mipmap/ic_launcher"
app:layout_constraintLeft_toRightOf="#+id/imageView3"
app:layout_constraintTop_toTopOf="#+id/imageView3"
app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>
I've found the solution: Group views in ConstraintLayout to treat them as a single view
Using chains, multiple views could be treated like a group.