Why is my layout not filling the screen in landscape mode? - java

I have the following layout for a video player:
video_view.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.exoplayer2.ui.AspectRatioFrameLayout
android:id="#+id/aspectRatioLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center">
<SurfaceView
android:id="#+id/surfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="#+id/posterImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="#string/poster_image_description" />
<com.google.android.exoplayer2.ui.SubtitleView
android:id="#+id/subtitleView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.exoplayer2.ui.PlayerControlView
android:id="#+id/nativeControls"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.google.android.exoplayer2.ui.PlayerControlView>
<com.sdk.adapters.controls.ControlBar
android:id="#+id/controls"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</com.sdk.adapters.controls.ControlBar>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/messageOverlay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#80000000">
<TextView
android:id="#+id/messageOverlayText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="#string/message_overlay"
android:textColor="#android:color/white"
android:textSize="30sp" />
</FrameLayout>
</FrameLayout>
</com.google.android.exoplayer2.ui.AspectRatioFrameLayout>
</FrameLayout>
The ControlBar is defined as:
control_bar_view.xml
<androidx.constraintlayout.widget.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="#80000000">
<!-- BEGIN: Strut -->
<View
android:id="#+id/exitPlaceholder"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.1" />
<!-- END: Strut -->
<TextView
android:id="#+id/broadcastName"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="#string/broadcast_name"
android:textColor="#ffffff"
android:textSize="18sp"
app:layout_constraintEnd_toStartOf="#id/castButton"
app:layout_constraintStart_toEndOf="#id/exitPlaceholder"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/siteName"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="#string/site_name"
android:textColor="#ffffff"
android:textSize="18sp"
app:layout_constraintEnd_toStartOf="#id/castButton"
app:layout_constraintStart_toEndOf="#id/exitPlaceholder"
app:layout_constraintTop_toBottomOf="#id/broadcastName" />
<ImageButton
android:id="#+id/castButton"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="10dp"
android:contentDescription="#string/send_to_google_chromecast"
android:visibility="invisible"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toStartOf="#id/airplayButton"
app:layout_constraintHeight_percent="0.1"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="#+id/airplayButton"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="10dp"
android:contentDescription="#string/send_to_apple_airplay"
android:visibility="invisible"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toStartOf="#id/optionsButton"
app:layout_constraintHeight_percent="0.1"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="#+id/optionsButton"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="10dp"
android:background="#android:color/transparent"
android:contentDescription="#string/fullscreen"
android:scaleType="fitStart"
android:src="#drawable/closed_caption_gray"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.1"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="#+id/skipBackButton"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#android:color/transparent"
android:contentDescription="#string/skip_back_button"
android:scaleType="fitStart"
android:src="#drawable/back_30"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toStartOf="#id/playPauseToggle"
app:layout_constraintHeight_percent="0.20"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="#+id/playPauseToggle"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#android:color/transparent"
android:contentDescription="#string/play_button"
android:scaleType="fitStart"
android:src="#drawable/play"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toStartOf="#id/skipForwardButton"
app:layout_constraintHeight_percent="0.25"
app:layout_constraintStart_toEndOf="#id/skipBackButton"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="#+id/skipForwardButton"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#android:color/transparent"
android:contentDescription="#string/skip_forward_button"
android:scaleType="fitStart"
android:src="#drawable/forward_30"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.20"
app:layout_constraintStart_toEndOf="#id/playPauseToggle"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/currentTime"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_margin="10dp"
android:text="#string/null_time"
android:textColor="#ffffff"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="#id/seekBar"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/remainingTime"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_margin="10dp"
android:text="#string/null_time"
android:textColor="#ffffff"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="#id/seekBar"
app:layout_constraintEnd_toEndOf="parent" />
<SeekBar
android:id="#+id/seekBar"
android:layout_width="0dp"
android:layout_height="0dp"
android:progress="50"
android:progressDrawable="#drawable/seek_bar"
android:thumb="#drawable/seek_thumb"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#id/fullscreenButton"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#id/fullscreenButton"
app:layout_constraintVertical_bias="0.0" />
<ImageButton
android:id="#+id/fullscreenButton"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="10dp"
android:background="#android:color/transparent"
android:contentDescription="#string/fullscreen"
android:scaleType="fitStart"
android:src="#drawable/fullscreen"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.1" />
</androidx.constraintlayout.widget.ConstraintLayout>
In the layout editor in Android Studio, this looks good:
However when I run an actual app, the ControlBar (and only the ControlBar) isn't filling the screen! Everything else stretches to fill the screen perfectly:
What am I doing wrong?
If it helps, the ControlBar is a custom View which extends ConstraintLayout. Here's what the initialization code looks like:
ControlBar.java
public class ControlBar extends ConstraintLayout
{
private BFPlayer player;
private TextView broadcastName;
// ... references for the various subviews ...
private ImageButton fullscreenButton;
public ControlBar ( Context context )
{
super(context);
init(context);
}
public ControlBar ( Context context, AttributeSet attrs )
{
super(context, attrs);
init(context);
}
public ControlBar ( Context context, AttributeSet attrs, int defStyleAttr )
{
super(context, attrs, defStyleAttr);
init(context);
}
private void init ( Context context )
{
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.bf_control_bar_view, null);
addView(view);
broadcastName = findViewById(R.id.broadcastName);
// ... grab references to the various buttons ...
fullscreenButton = findViewById(R.id.fullscreenButton);
// ... set up listeners for the various buttons ...
}
// ... The rest of the class ...
}
What am I doing wrong? I'm sure it's something simple, but I've been staring for a minute and can't figure it out. (Note: I'm pretty new to Android development, and not very experienced. My job has me changing platforms and programming languages very often)

You're not telling it what the parent is when you inflate your View, so it doesn't apply the LayoutParams correctly:
View view = inflater.inflate(R.layout.bf_control_bar_view, null);
addView(view);
Instead, tell it to inflate directly into the parent:
View view = inflater.inflate(R.layout.bf_control_bar_view, this);

Related

Scrolling scrollview programmatically when keyboard is shown

I have been searching for a long time, but none of the answers were helpful.
I'm making a chat app. When the user clicks on input edit text the keyboard shows up, and I want to automatically scroll to the bottom of scroll view, but it does not work as expected. It looks like it thinks that the scrollview has different dimensions than it really has. (probably doesn't realize that keyboard is taking some space)
When keyboard is hidden, programitacally scrolling to the bottom works as expected.
This is what i have now:
In manifest:
<activity
android:name=".ChatActivity"
android:windowSoftInputMode="adjustResize"
android:screenOrientation="portrait" />
In activity:
messageEditText.setOnFocusChangeListener(new View.OnFocusChangeListener()
{
#Override
public void onFocusChange(View v, boolean hasFocus)
{
if (!hasFocus)
{
HideKeyboard(v);
// ScrollToBottom ();
}
else
{
ScrollToBottom();
messagesScrollView.post(new Runnable() {
#Override
public void run() {
messageEditText.requestFocus();
}
});
ScrollToBottom();
}
}
});
private void ScrollToBottom ()
{
messagesLinearLayout.requestLayout();
messagesLinearLayout.post(new Runnable() {
#Override
public void run() {
messagesScrollView.scrollTo(0, messagesScrollView.getBottom());
}
});
}
Layout file:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="#color/black"
android:clickable="true"
android:focusableInTouchMode="true"
tools:context=".ChatActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Theme.LetsGOFriends.AppBarOverlay"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="66dp"
android:background="#242A2F"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
app:contentInsetEnd="0dp"
app:buttonGravity="center_vertical"
app:popupTheme="#style/Theme.LetsGOFriends.PopupOverlay">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|start">
<TextView
android:id="#+id/trainerNameChat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/profilePictureImageView"
android:layout_marginStart="10dp"
android:layout_marginTop="-2dp"
android:layout_toEndOf="#+id/profilePictureImageView"
android:maxLines="1"
android:textSize="14sp"
android:text="LoriMontana"
android:textColor="#color/white" />
<TextView
android:id="#+id/trainerCodeChat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/profilePictureImageView"
android:layout_alignStart="#+id/trainerNameChat"
android:layout_marginBottom="-2dp"
android:layout_marginStart="0dp"
android:maxLines="1"
android:textSize="14sp"
android:text="0467 0321 3849"
android:textColor="#color/white" />
<com.google.android.material.imageview.ShapeableImageView
android:id="#+id/profilePictureImageView"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="15dp"
android:layout_marginStart="0dp"
android:layout_marginTop="15dp"
android:padding="1dp"
app:shapeAppearanceOverlay="#style/roundedImageViewRounded"
app:srcCompat="#drawable/ic_default_profile_picture"
app:strokeColor="#484848"
app:strokeWidth="1dp" />
<ImageView
android:id="#+id/languageFlagChatImageView"
android:layout_width="18dp"
android:layout_height="16dp"
android:layout_alignBottom="#+id/trainerNameChat"
android:layout_alignTop="#+id/trainerNameChat"
android:layout_marginBottom="4dp"
android:layout_marginStart="5dp"
android:layout_marginTop="4dp"
android:layout_toEndOf="#+id/trainerNameChat"
tools:srcCompat="#tools:sample/avatars" />
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<ScrollView
android:id="#+id/messagesScrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="-15dp"
android:focusableInTouchMode="true"
app:layout_constraintBottom_toTopOf="#+id/cardView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/appBarLayout">
<LinearLayout
android:id="#+id/messagesLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusableInTouchMode="true"
android:paddingBottom="20dp"
android:paddingTop="5dp"
android:orientation="vertical"
android:focusable="true" />
</ScrollView>
<androidx.cardview.widget.CardView
android:id="#+id/cardView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cardBackgroundColor="#android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:cardCornerRadius="0dp"
app:cardElevation="0dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout2"
style="#style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
app:boxBackgroundColor="#242A2F"
app:boxCornerRadiusBottomEnd="15dp"
app:boxCornerRadiusBottomStart="15dp"
app:boxCornerRadiusTopEnd="15dp"
app:boxCornerRadiusTopStart="15dp"
app:boxStrokeColor="#color/teal_700"
app:boxStrokeWidth="0dp"
app:boxStrokeWidthFocused="0dp"
app:endIconContentDescription="Send"
app:endIconDrawable="#drawable/ic_baseline_send_24"
app:endIconMode="custom"
app:endIconTint="#color/white"
app:hintEnabled="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Enter your message.."
android:maxLength="250"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:textColor="#color/white"
android:textColorHint="#D3D3D3" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
I think it's something wrong with layout file.
Try this code for scrolling down:
messagesScrollView.fullScroll(ScrollView.FOCUS_DOWN);

I can't scroll the recyclerview even though it display all of the items

Recyclerview shows all the items, but I can't scroll it. Also in a way that I can't understand, once I click and open the searchView, I'm able to scroll just a bit (still not fully). How can I get the recyclerview to scroll?
Here is the Constraint Layout that includes Recycler View
<androidx.constraintlayout.widget.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="#color/colorPrimaryDark"
tools:context=".MainActivity">
<TextView
android:id="#+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:paddingStart="#dimen/_10sdp"
android:paddingTop="#dimen/_10sdp"
android:text="#string/notes"
android:textColor="#color/ColorWhite"
android:textSize="#dimen/_15sdp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<SearchView
android:queryHint="#string/search"
android:theme="#style/ThemeOverlay.search"
android:iconifiedByDefault="false"
android:id="#+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/_10sdp"
android:background="#drawable/background"
android:searchIcon="#drawable/ic_search"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/tv1" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view"
android:nestedScrollingEnabled="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/_10sdp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:overScrollMode="never"
app:layout_constraintTop_toBottomOf="#id/search_view" />
<LinearLayout
android:id="#+id/l1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:orientation="horizontal"
android:padding="#dimen/_10sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_tick"
app:tint="#color/ColorWhite" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_10sdp"
android:layout_marginEnd="#dimen/_10sdp"
android:src="#drawable/ic_baseline_image_24"
app:tint="#color/ColorWhite" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_baseline_insert_link_24"
app:tint="#color/ColorWhite" />
</LinearLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fabCreateNote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_baseline_add_24"
android:backgroundTint="#color/colorAccent"
android:tint="#color/ColorWhite"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginEnd="#dimen/_20sdp"
android:layout_marginBottom="#dimen/_20sdp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
And here is the Recyclerview Adapter
class NotesAdapter() :
RecyclerView.Adapter<NotesAdapter.NotesViewHolder>() {
var listener: OnItemClickListener? = null
var arrList = ArrayList<Notes>()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NotesViewHolder {
return NotesViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.item_rv_notes, parent, false)
)
}
override fun getItemCount(): Int {
return arrList.size
}
fun setData(arrNotesList: List<Notes>) {
arrList = arrNotesList as ArrayList<Notes>
}
fun setOnClickListener(listener1: OnItemClickListener) {
listener = listener1
}
override fun onBindViewHolder(holder: NotesViewHolder, position: Int) {
holder.itemView.tvTitle.text = arrList[position].title
holder.itemView.tvDesc.text = arrList[position].noteText
holder.itemView.tvDateTime.text = arrList[position].dateTime
if (arrList[position].color != null){
holder.itemView.cardView.setCardBackgroundColor(Color.parseColor(arrList[position].color))
}else{
holder.itemView.cardView.setCardBackgroundColor(Color.parseColor(R.color.ColorLightBlack.toString()))
}
if (arrList[position].pathImage != null) {
holder.itemView.imgNote.setImageBitmap(BitmapFactory.decodeFile(arrList[position].pathImage))
holder.itemView.imgNote.visibility = View.VISIBLE
} else {
holder.itemView.imgNote.visibility = View.GONE
}
if (arrList[position].webLink != "") {
holder.itemView.tvWebLink.text = arrList[position].webLink
holder.itemView.tvWebLink.visibility = View.VISIBLE
} else {
holder.itemView.tvWebLink.visibility = View.GONE
}
holder.itemView.cardView.setOnClickListener {
listener!!.onClicked(arrList[position].pld!!)
}
}
class NotesViewHolder(view: View) : RecyclerView.ViewHolder(view){
}
interface OnItemClickListener {
fun onClicked(noteId: Int)
}
}```
Try placing the .xml content inside the Drawer layout
<androidx.drawerlayout.widget.DrawerLayout 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/colorPrimaryDark"
tools:context=".MainActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:paddingStart="#dimen/_10sdp"
android:paddingTop="#dimen/_10sdp"
android:text="#string/notes"
android:textColor="#color/ColorWhite"
android:textSize="#dimen/_15sdp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<SearchView
android:queryHint="#string/search"
android:theme="#style/ThemeOverlay.search"
android:iconifiedByDefault="false"
android:id="#+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/_10sdp"
android:background="#drawable/background"
android:searchIcon="#drawable/ic_search"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/tv1" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view"
android:nestedScrollingEnabled="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/_10sdp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:overScrollMode="never"
app:layout_constraintTop_toBottomOf="#id/search_view" />
<LinearLayout
android:id="#+id/l1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:orientation="horizontal"
android:padding="#dimen/_10sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_tick"
app:tint="#color/ColorWhite" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_10sdp"
android:layout_marginEnd="#dimen/_10sdp"
android:src="#drawable/ic_baseline_image_24"
app:tint="#color/ColorWhite" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_baseline_insert_link_24"
app:tint="#color/ColorWhite" />
</LinearLayout>
</FrameLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fabCreateNote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_baseline_add_24"
android:backgroundTint="#color/colorAccent"
android:tint="#color/ColorWhite"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginEnd="#dimen/_20sdp"
android:layout_marginBottom="#dimen/_20sdp"/>
</androidx.drawerlayout.widget.DrawerLayout>
Actually the problem isn't in the scrolling itself, but that the rest of the RecyclerView items can't be seen as they are behind the l1 LinearLayout.
To fix this you can adjust the ConstraintLayout constraints to attach a RecyclerView bottom constraints to the top of the l1, and make the height as 0dp to match constraints:
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="#dimen/_10sdp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="#+id/l1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/search_view" />

After trying a long not able to provide space between 2 card view elements inside a recycler view for both horizontal and vertical [duplicate]

This question already has answers here:
How to add dividers and spaces between items in RecyclerView
(45 answers)
Closed 2 years ago.
I want to add some space between 2 cards in both the horizontal recycler view and the vert recycler view but not able to add tried everything but won't getting a sol as u can see in the below image For horizontal both the cards are over each other.
My XML code in which I had defined recycler view Both hor. and ver. :-
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="#color/AppBackground">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="MissingConstraints">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="#color/AppBackground">
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:id="#+id/nestedsview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/appBar">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent">
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:fontFamily="#font/playfair_display_bold_italic"
android:text="Looking for a delecious cake?"
android:textColor="#android:color/black"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="#id/recyclerViewHorizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:fontFamily="#font/playfair_display_bold_italic"
android:text="More"
android:textColor="#android:color/black"
android:textSize="20sp"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="200dp"
android:layout_marginEnd="20dp"
android:text="Button"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="266dp" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerViewHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
app:layout_constraintBottom_toTopOf="#+id/textView6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.526"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linear"
tools:context=".FirstActivity">
</androidx.recyclerview.widget.RecyclerView>
<TextView
android:id="#+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginTop="10dp"
android:fontFamily="#font/playfair_display_bold_italic"
android:text="Best Selling"
android:textColor="#android:color/black"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="#+id/recyclerViewVertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/recyclerViewHorizontal" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerViewVertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginStart="30dp"
android:layout_marginTop="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView6"
tools:context=".FirstActivity"
>
</androidx.recyclerview.widget.RecyclerView>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
My Xml Code for card :
<?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="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp"
>
<androidx.cardview.widget.CardView
android:id="#+id/cardView"
android:layout_width="170dp"
android:layout_height="220dp"
android:padding="10dp"
android:elevation="10dp"
app:cardBackgroundColor="#color/CardColor"
app:cardCornerRadius="25sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraint"
android:layout_width="130dp"
android:layout_height="180dp"
android:layout_gravity="center"
android:background="#color/CardColor"
android:padding="5dp">
<ImageView
android:id="#+id/imageView"
android:layout_width="90dp"
android:layout_height="100dp"
android:foregroundGravity="center_horizontal"
android:scaleType="fitXY"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:fontFamily="#font/playfair_display_bold_italic"
android:gravity="center"
android:text="Great"
android:textColor="#android:color/black"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView" />
<TextView
android:id="#+id/textViewForPieceInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:fontFamily="#font/playfair_display_bold_italic"
android:text="Ram"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView4" />
<TextView
android:id="#+id/textViewforPrice"
android:text="Shyam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:fontFamily="#font/playfair_display_bold_italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textViewForPieceInfo" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginBottom="2dp"
app:fabSize="mini"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="#drawable/ic_baseline_add_24" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
My recycler view class code:
package com.example.cako;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.widget.Toolbar;
import android.os.Bundle;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
public class FirstActivity extends AppCompatActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
String []x={"Aaran", "Aaren", "Aarez", "Aarman", "Aaron", "Aaron-James", "Aarron", "Aaryan", "Abhinav","Ankit"};
String []image= {"https://upload.wikimedia.org/wikipedia/commons/thumb/c/c8/Aloo_gobi.jpg/180px-Aloo_gobi.jpg",
"https://upload.wikimedia.org/wikipedia/commons/thumb/c/c8/Aloo_gobi.jpg/180px-Aloo_gobi.jpg",
"https://upload.wikimedia.org/wikipedia/commons/thumb/d/d1/Aloo_Tikki_served_with_chutneys.jpg/180px-Aloo_Tikki_served_with_chutneys.jpg",
"https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/Aloo_Mattar.jpg/180px-Aloo_Mattar.jpg",
"https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/Aloo_Methi_%28Aaloo_Methi%29.JPG/180px-Aloo_Methi_%28Aaloo_Methi%29.JPG",
"https://upload.wikimedia.org/wikipedia/commons/thumb/b/b0/Spicy_alloo_with_tadka_mirchi.jpg/180px-Spicy_alloo_with_tadka_mirchi.jpg",
"https://upload.wikimedia.org/wikipedia/commons/thumb/c/c8/Aloo_gobi.jpg/180px-Aloo_gobi.jpg",
"https://upload.wikimedia.org/wikipedia/commons/thumb/c/c8/Aloo_gobi.jpg/180px-Aloo_gobi.jpg",
"https://upload.wikimedia.org/wikipedia/commons/thumb/d/d1/Aloo_Tikki_served_with_chutneys.jpg/180px-Aloo_Tikki_served_with_chutneys.jpg",
"https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/Aloo_Mattar.jpg/180px-Aloo_Mattar.jpg"
};
Toolbar toolbar=findViewById(R.id.toolbar) ;
setSupportActionBar(toolbar);
RecyclerView horizontalrecyclerView =(RecyclerView)findViewById(R.id.recyclerViewHorizontal);
horizontalrecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL,false));
horizontalrecyclerView.setAdapter(new RecyclerVview(this,x,image));
RecyclerView verticalrecyclerView =(RecyclerView)findViewById(R.id.recyclerViewVertical);
verticalrecyclerView.setLayoutManager(new GridLayoutManager(this,2));
verticalrecyclerView.setAdapter(new RecyclerVview(this,x,image));
}
}
class RecyclerVview extends RecyclerView.Adapter<RecyclerVview.Holder>{
Activity co;
String[] name;
String[] image;
public RecyclerVview(Context applicationContext, String[] x, String[] image) {
co=(Activity)applicationContext;
name=x;
this.image=image;
}
#NonNull
#Override
public Holder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v=LayoutInflater.from(co).inflate(R.layout.layout_for_horizontal_recyclerview,parent,false);
return new Holder(v);
}
#Override
public void onBindViewHolder(#NonNull final Holder holder, int position) {
holder.textViewForItemName.setText(name[position]);
Glide.with(co).load(image[position]).into(holder.image);
holder.floatingActionButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(co, "yesWorking", Toast.LENGTH_SHORT).show();
Log.i("yes","log");
}
});
holder.textViewForPrice.setText("30$");
holder.textViewForPieceInfo.setText("Single Piece Only.");
}
#Override
public int getItemCount() {
return name.length;
}
public class Holder extends RecyclerView.ViewHolder{
ImageView image;
TextView textViewForItemName;
FloatingActionButton floatingActionButton;
TextView textViewForPrice;
TextView textViewForPieceInfo;
public Holder(#NonNull View itemView) {
super(itemView);
image=itemView.findViewById(R.id.imageView);
textViewForItemName=itemView.findViewById(R.id.textView4);
floatingActionButton=itemView.findViewById(R.id.floatingActionButton);
textViewForPieceInfo=itemView.findViewById(R.id.textViewForPieceInfo);
textViewForPrice=itemView.findViewById(R.id.textViewforPrice);
}
}
}
Add margin for the CarView layout and inside the ContraintLayout
and Use this for your card.
<?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="wrap_content"
android:layout_height="wrap_content"
android:margin="8dp"
>
<androidx.cardview.widget.CardView
android:id="#+id/cardView"
android:layout_width="170dp"
android:layout_height="220dp"
android:margin="8dp"
android:elevation="10dp"
app:cardBackgroundColor="#color/CardColor"
app:cardCornerRadius="25sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraint"
android:layout_width="130dp"
android:layout_height="180dp"
android:layout_gravity="center"
android:background="#color/CardColor"
android:padding="5dp">
<ImageView
android:id="#+id/imageView"
android:layout_width="90dp"
android:layout_height="100dp"
android:foregroundGravity="center_horizontal"
android:scaleType="fitXY"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:fontFamily="#font/playfair_display_bold_italic"
android:gravity="center"
android:text="Great"
android:textColor="#android:color/black"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView" />
<TextView
android:id="#+id/textViewForPieceInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:fontFamily="#font/playfair_display_bold_italic"
android:text="Ram"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView4" />
<TextView
android:id="#+id/textViewforPrice"
android:text="Shyam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:fontFamily="#font/playfair_display_bold_italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textViewForPieceInfo" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginBottom="2dp"
app:fabSize="mini"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="#drawable/ic_baseline_add_24" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

Fragment is not added to the back stack when replaced

Above is the path I follow until I reach the BeginnerFragment.
Above is the hierarchy of activity / fragments
Current Situation
In my application I have a Bottom Navigation, and in each fragment of the navigation, I have two tabs.
The Problem
My problem is that when I'm at BeginnerFragment and I press the cell back button, it returns to the StatusFragment.
I expected it to return to EducationHomeFragment, as I added it to BackStack, according to the codes below.
EducationFragment
public class EducationFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View root = inflater.inflate(R.layout.fragment_education, container, false);
// Instanciando o Fragmento de página inicial da Educação
EducationHomeFragment educationHomeFragment = new EducationHomeFragment();
getActivity().getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container, educationHomeFragment).addToBackStack(null).commit();
return root;
}
}
fragment_education
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/fragment_container"
tools:context=".education.EducationFragment"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
EducationHomeFragment
public class EducationHomeFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View root = inflater.inflate(R.layout.fragment_education_home, container, false);
CardView beginnerFreelance = root.findViewById(R.id.cardview_beginner_skills);
beginnerFreelance.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
BeginnerFragment fragment = new BeginnerFragment();
getActivity().getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container , fragment)
.addToBackStack(null)
.commit();
}
});
return root;
}
}
fragment_education_home
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/fragment_education_home_container"
tools:context=".education.EducationHomeFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EEE"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/text_academic_education"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="#string/academic_education"
android:textColor="#color/colorPrimaryDark"
app:fontFamily="#font/exo_2_semibold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardview_advanced_skills" />
<TextView
android:id="#+id/title_courses_available"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="#string/general_courses"
android:textColor="#color/colorPrimaryDark"
app:fontFamily="#font/exo_2_semibold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardview_qualifications" />
<androidx.cardview.widget.CardView
android:id="#+id/cardview_doctoral_courses"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="#dimen/default_cardview_mgsides"
android:layout_marginTop="#dimen/cardview_list_margin"
android:layout_marginRight="#dimen/default_cardview_mgsides"
android:layout_marginBottom="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardview_master_courses">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView39"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/doctoral_courses"
app:fontFamily="#font/exo_2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardview_master_courses"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="#dimen/default_cardview_mgsides"
android:layout_marginTop="#dimen/cardview_list_margin"
android:layout_marginRight="#dimen/default_cardview_mgsides"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardview_specialization_courses">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView38"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/master_courses"
app:fontFamily="#font/exo_2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardview_specialization_courses"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="#dimen/default_cardview_mgsides"
android:layout_marginTop="#dimen/cardview_list_margin"
android:layout_marginRight="#dimen/default_cardview_mgsides"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardview_higher_courses">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/text_doctoral_courses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/specialization_courses"
app:fontFamily="#font/exo_2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardview_higher_courses"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="#dimen/default_cardview_mgsides"
android:layout_marginTop="#dimen/cardview_list_margin"
android:layout_marginRight="#dimen/default_cardview_mgsides"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text_academic_education">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/text_master_courses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/higher_level_courses"
app:fontFamily="#font/exo_2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardview_advanced_skills"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="#dimen/default_cardview_mgsides"
android:layout_marginTop="#dimen/cardview_list_margin"
android:layout_marginRight="#dimen/default_cardview_mgsides"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardview_intermediate_skills">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/text_specialization_courses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/advanced"
app:fontFamily="#font/exo_2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardview_study_status"
android:layout_width="match_parent"
android:layout_height="85dp"
android:layout_marginLeft="#dimen/default_cardview_mgsides"
android:layout_marginTop="#dimen/default_cardview_mgtop"
android:layout_marginRight="#dimen/default_cardview_mgsides"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image_study_status"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginTop="10dp"
android:tint="#color/colorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/outline_menu_book_24" />
<TextView
android:id="#+id/text_study_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="#string/not_studying"
android:textColor="#color/colorPrimaryDark"
app:fontFamily="#font/exo_2_semibold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/image_study_status" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardview_qualifications"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/default_cardview_mgsides"
android:layout_marginTop="#dimen/default_cardview_mgtop"
android:layout_marginRight="#dimen/default_cardview_mgsides"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardview_study_status">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="12dp"
android:paddingBottom="12dp">
<TextView
android:id="#+id/title_obtained_qualifications"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/qualifications_obtained"
android:textColor="#color/colorPrimaryDark"
app:fontFamily="#font/exo_2_semibold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/obtained_qualification_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="#string/no_course_completed"
app:fontFamily="#font/exo_2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/title_obtained_qualifications" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardview_beginner_skills"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="#dimen/default_cardview_mgsides"
android:layout_marginTop="#dimen/cardview_list_margin"
android:layout_marginRight="#dimen/default_cardview_mgsides"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/title_courses_available">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/text_basic_courses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/beginner"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardview_intermediate_skills"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="#dimen/default_cardview_mgsides"
android:layout_marginTop="#dimen/cardview_list_margin"
android:layout_marginRight="#dimen/default_cardview_mgsides"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardview_beginner_skills">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/text_higher_courses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/intermediate"
app:fontFamily="#font/exo_2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
Why isn't FragmentEducationHome being added to the stack? I want to return to FragmentEducationHome when I click on the BeginnerFragment back button.
This is not a direct answer to the question.
But Google suggests to use Jetpack Navigation approach.
Which will be single Activity and multiple fragments.
Google Code Labs Link
This avoids lot of bipolarate code , were we had to handle backstack, keeping fragment count etc...
At first anyone will feel bit difficult to start with, but in a while , you can grasp and move on to new approach which is suggestible.
Nav_graph avoids programmers responsibility to add/ remove fragments
Allows passing data (raw data or data classes with Parcelable) from one fragment to another
Moving from one child nav graph to another
And much more...
I would suggest you do checkout this once starting with a new trial/project
EDIT
Even though one activity is suggested, we may have more than one Activity and its corresponding child fragment graphs if required. This purely depends on the requirement. In my last project we started with single activity concept. But as the app complexity increased, it was decided to move for two activity and its corresponding child frags.
With respect to Clean Code Architecture this is easily adaptable as well...
Good luck!
Please refer to this question:
Override onBackPressed() into your activity and call this in order to remove current fragment from backstack, since you add it.
if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
getSupportFragmentManager().popBackStackImmediate()
} else {
finish();
}
Make sure R.id.fragment_container lives in the parent activity xml (not the fragment xml) and in EducationHomeFragment use .add instead of .replace to add BeginnerFragment to the back stack
You already replace current container fragment by BeginnerFragment, so you can't back to previous fragment. Try to use add(id, fragment, tag) and addToBackStack(tag). Hope help you.

Prevent Reload WebView onResume()

After lock my screen and unlock pressing the turn off button my webview is reloaded.
I have found that problem is with onResume()
#Override
protected void onResume() {
super.onResume();
mWebView.onResume();
mWebView.resumeTimers();
}
Reload is happen only with webview, as i can see navigation bar at the bottom is untouched. So how to prevent reloading webview also i will need onResume() for future use so removing is not solution.
Here is Activity layout
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
android:windowTranslucentNavigation="false"
tools:context=".MainActivity">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/swipeRefresh"
android:layout_width="0dp"
android:layout_height="0dp"
android:overScrollMode="never"
android:soundEffectsEnabled="true"
app:layout_constrainedHeight="true"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toTopOf="#id/BottomLayout"
app:layout_constraintEnd_toEndOf="#id/BottomLayout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:scrollbars="none"
android:visibility="gone" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<include
android:id="#+id/netCon"
layout="#layout/network_connection" />
<include
android:id="#+id/srvCon"
layout="#layout/server_connection" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/BottomLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:animateLayoutChanges="true"
android:background="#drawable/border_top_bottom_menu"
android:clipToPadding="false"
android:duplicateParentState="false"
android:fitsSystemWindows="false"
android:focusableInTouchMode="false"
android:theme="#style/bottom_navigation_menu"
android:visibility="visible"
app:barrierAllowsGoneWidgets="true"
app:itemHorizontalTranslationEnabled="false"
app:itemIconSize="22dp"
app:itemIconTint="#color/drawer_item"
app:itemTextColor="#color/drawer_item"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toTopOf="#id/Notification"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:menu="#menu/bottom_navigation_menu">
</com.google.android.material.bottomnavigation.BottomNavigationView>
<LinearLayout
android:id="#+id/Notification"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#color/notification_offline"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical"
android:weightSum="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<TextView
android:id="#+id/notificationText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="12sp"
android:textStyle="normal" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<ProgressBar
android:id="#+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center|center_vertical"
android:indeterminate="false"
android:theme="#style/progressWhite"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Try saving the state of the webview and only loading it when savedstate is not null
#Override
protected void onSaveInstanceState(Bundle outState )
{
super.onSaveInstanceState(outState);
web.saveState(outState);
}
#Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onRestoreInstanceState(savedInstanceState);
web.restoreState(savedInstanceState);
}

Categories

Resources