I have been having an issue with my card view where android studio is putting way too much space in between them. Here is an example screenshot I took from the emulator. For my layout inflater here is the code I used:
#Override
public DriveStatsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType)
{
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.cardview_layout, viewGroup, false);
DriveStatsViewHolder dsvh = new DriveStatsViewHolder(v);
return dsvh;
}
Below is my cardview_layout.xml
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="#+id/cv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
>
<TextView
android:id="#+id/FinishTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/Drive_Date"
android:layout_toStartOf="#+id/Total_Drive_Time"
android:textAlignment="textEnd"
android:textSize="18sp"
tools:text="Finish Time"/>
<TextView
android:id="#+id/Total_Drive_Time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:textAlignment="viewStart"
android:textSize="18sp"
tools:text="Total Drive Time"/>
<TextView
android:id="#+id/Drive_Date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:textSize="24sp"
tools:text="Default Text"/>
<TextView
android:id="#+id/Start_Time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/Drive_Date"
android:textSize="18sp"
tools:text="Start Time"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
I am pretty new to android studio so any help would be appreciated.
Your outer RelativeLayout's height is match_parent, so each item in your list is as tall as your screen. However, the CardView itself only has a height of wrap_content, so most of that space is going to be left empty.
Related
I have a question about the items height in a recyclerview, here is my screen
Is it possible to have the same height for each rows like that for example:
So the first one has to have the same height of the second and the third the same as the 4th one.
Currently I used wrap-content that's why the height is changing regarding the content of the cardview but I would like to use smt dynamic if it possible and not put a fixed height.
Here is my code
<MvvmCross.DroidX.RecyclerView.MvxRecyclerView
android:id="#+id/recyclerViewSalary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
app:layout_constraintTop_toBottomOf="#id/lblSalary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:MvxItemTemplate="#layout/cell_tool_cardview"
app:MvxBind="ItemClick OpenTool;ItemsSource SalarisToolItems"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="2"/>
and the itemtemplate
<?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:layout_marginEnd="#dimen/margin2"
android:layout_marginStart="#dimen/margin2"
android:layout_marginBottom="#dimen/margin2"
android:layout_marginTop="#dimen/margin2"
app:cardCornerRadius="#dimen/margin1"
app:cardElevation="0dp"
app:MvxBind="Visibility Visibility(Available)">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/margin4"
android:background="#color/lightBlue">
<FrameLayout
android:id="#+id/frameLayoutCellTool"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin5"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<ImageView
android:id="#+id/imgTool"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_gravity="center"
android:scaleType="centerInside"
android:tint="#color/blue"
app:MvxBind="DrawableName ImageDrawable"/>
</FrameLayout>
<TextView
android:id="#+id/lblTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin3"
android:layout_marginEnd="#dimen/margin3"
android:textColor="#color/blue"
android:fontFamily="#font/poppins_semibold"
android:textSize="#dimen/t4"
android:gravity="center"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/frameLayoutCellTool"
app:MvxBind="Text Title"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="#dimen/t2"
android:gravity="center"
android:fontFamily="#font/mulish_regular"
android:textColor="#color/blue"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/lblTitle"
app:MvxBind="Text SubTitle; Visibility InvertedVisibility(IsEmptySubTitle)"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
Anyone has an idea ? Thanks
I have one parent Horizontal Recycleview which contains twelve Vertical Recycleviews. I would like to show only two columns per page, on only one horizontal row. I use GridLayoutManager.
GridLayoutManager layoutManager = new GridLayoutManager(this,1);
layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
Increasing span to 2 it creates two rows which i don't want.
Also i tried layout:width in xml to fixed value in dp or sp that results in different number of columns on different screen sizes.
xml for each block
<?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"
android:id="#+id/view_table_view_game_block_constraint_layout"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:background="#drawable/shape_round_top"
android:layout_marginTop="8dp">
<TextView
android:id="#+id/textView_table_view_odds_block_time"
android:layout_width="0dp"
android:layout_height="50sp"
android:gravity="center_vertical"
android:textColor="#color/colorFontWhite"
android:textSize="#dimen/font_size"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button_table_view_odds_block_hometeam"
android:layout_width="0dp"
android:layout_height="50sp"
android:layout_marginTop="4dp"
android:textAlignment="textStart"
android:background="#android:color/transparent"
android:textColor="#color/colorFontWhite"
android:textSize="#dimen/font_size"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView_table_view_odds_block_time" />
<Button
android:id="#+id/button_table_view_odds_block_drawable"
android:layout_width="0dp"
android:layout_height="50sp"
android:layout_marginTop="4dp"
android:background="#android:color/transparent"
android:textAlignment="textStart"
android:textColor="#color/colorFontWhite"
android:textSize="#dimen/font_size"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button_table_view_odds_block_hometeam" />
<Button
android:id="#+id/button_table_view_game_odds_awayteam"
android:layout_width="0dp"
android:layout_height="50sp"
android:layout_marginTop="4dp"
android:background="#android:color/transparent"
android:textAlignment="textStart"
android:textColor="#color/colorFontWhite"
android:textSize="#dimen/font_size"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button_table_view_odds_block_drawable" />
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Set width dynamically according to the screen size. this is the best way to get perfect result.
Update onBindViewHolder of your Horizontal Recyclerview like that.
#Override
public void onBindViewHolder(#NonNull UsersAdapter.UsersAdapterVh holder, int position) {
UserModel userModel = userModelList.get(position);
String username = userModel.getUserName();
String prefix = userModel.getUserName().substring(0,1);
holder.tvUsername.setText(username);
holder.tvPrefix.setText(prefix);
holder.item_layout.getLayoutParams().width = getScreenWidth(context)/2;
}
public static int getScreenWidth(Context context) {
WindowManager wm= (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(dm);
return dm.widthPixels;
}
This is how the RecyclerView item layout looks like for the given example.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:padding="10dp"
android:id="#+id/holder_view"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="50dp"
android:background="#drawable/users_bg"
android:layout_height="50dp">
<TextView
android:id="#+id/prefix"
android:layout_width="wrap_content"
android:textSize="16sp"
android:textColor="#color/headerColor"
android:text="T"
android:layout_centerInParent="true"
android:layout_height="wrap_content"/>
</RelativeLayout>
<TextView
android:id="#+id/username"
android:layout_width="wrap_content"
android:textSize="16sp"
android:textColor="#color/headerColor"
android:text="username"
android:layout_marginStart="90dp"
android:layout_centerVertical="true"
android:layout_height="wrap_content"/>
<ImageView
android:layout_width="wrap_content"
android:id="#+id/imageView"
android:layout_margin="10dp"
android:layout_alignParentEnd="true"
android:src="#drawable/ic_navigate_next_black_24dp"
android:layout_height="wrap_content"/>
</RelativeLayout>
</LinearLayout>
Here is my Code that is used in RecyleViewAdapater!
val yearOfMemory = SimpleDateFormat("yyyy").format(memory.timeOfMemory)
// if year not show before, show it.
if (!yearSet.contains(yearOfMemory)) {
holder.yearOfMemories.visibility = View.VISIBLE
holder.yearOfMemories.text = yearOfMemory
yearSet.add(yearOfMemory)
}
Here is my ReccleView 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="wrap_content"
tools:layout_editor_absoluteY="81dp">
<TextView
android:id="#+id/month_and_day_of_memory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/content_of_memory"
app:layout_constraintHorizontal_bias="0.8"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/content_of_memory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.6"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/year_of_group_memory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:textSize="36sp"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="#+id/month_and_day_of_memory"
app:layout_constraintEnd_toStartOf="#+id/month_and_day_of_memory"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Like this, I already have set TextView(#+id/year_of_group_memory) Gone, but it still takes up space at the second item,and it don't take up at the third item.
I have tried all kinds. So, how can I fix it.?
I turn on the layout bounds.
So,how can cut off the below height,now?
Is your code in a RecyclerView adapter? If so, you must explicitly hide it due to the view recycling mechanism. Always have explicit if-else statements when hiding/showing views.
val yearOfMemory = SimpleDateFormat("yyyy").format(memory.timeOfMemory)
if (!yearSet.contains(yearOfMemory)) {
holder.yearOfMemories.visibility = View.VISIBLE
holder.yearOfMemories.text = yearOfMemory
yearSet.add(yearOfMemory)
} else {
holder.yearOfMemories.visibility = View.GONE
}
Also try replacing your viewholder contents with the following xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/year_of_group_memory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textSize="36sp"
android:lines="2"
tools:text="2017"
/>
<TextView
android:id="#+id/month_and_day_of_memory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/year_of_group_memory"
android:layout_alignBottom="#id/year_of_group_memory"
android:layout_margin="8dp"
android:textSize="18sp"
tools:text="03-11"
/>
<TextView
android:id="#+id/content_of_memory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/month_and_day_of_memory"
android:layout_alignTop="#id/month_and_day_of_memory"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:textSize="18sp"
tools:text="第一次接吻"
/>
</RelativeLayout>
If you use this, you have to set the height of yearOfMemories to 0 or wrap_content accordingly.
Try this:
<TextView
android:id="#+id/year_of_group_memory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
you hide this TextView but youre putting android:textSize="36sp" that it shouldn't have and other margins and app:layout_constraintBottom_toTopOf=
In my layout, the last view (Blue Text) is getting cropped like shown in the image below.
I have my ConstraintLayout setup like follows
<?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="wrap_content">
<ImageView
android:id="#+id/ivIcon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="10dp"
android:background="#color/blue"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="#+id/tvMain"
style="#style/ActorTextMainOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="28dp"
android:text="28"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="#+id/tvSecondaryOne"
style="#style/ActorTextSecondary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="4dp"
android:text="Jun"
app:layout_constraintBottom_toTopOf="#+id/tvSecondaryTwo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/tvMain"/>
<TextView
android:id="#+id/tvSecondaryTwo"
style="#style/ActorTextSecondary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="4dp"
android:text="2017"
app:layout_constraintBottom_toBottomOf="#+id/tvMain"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/tvMain"/>
<TextView
android:id="#+id/tvDescription"
style="#style/ActorTextDescription"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="4dp"
android:text="#string/arrival_date"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/tvMain"
app:layout_constraintTop_toBottomOf="#+id/tvSecondaryTwo"/>
</android.support.constraint.ConstraintLayout>
ConstraintLayout version being used is 1.0.2
I think I am missing something obvious here but I am unable to figure it out. How can I make the blue text at the bottom fully visible while keeping the ConstraintLayout's height to wrap_content?
Try Changing
app:layout_constraintTop_toBottomOf="#+id/tvSecondaryTwo"
to
app:layout_constraintTop_toBottomOf="#+id/tvMain"
for textview with id tvDescription
This makes the textview with id tvDescription to be below the textview with id tvMain.
I've attached 3 screenshots of a DialogFragment. In this dialog, I wanna show a RecyclerView. When the dialog opens, the width of first 2 items is shrunk. But after a little bit of scrolling when 3rd item comes up, it is displayed with expected width[Check screenshot 1 & 2]. If I continue scrolling from top to bottom then I see the rest of the items shown normally. Then again I scroll from bottom to top and surprisingly noticed that 1st and 2nd items are also shown as expected.[check screenshot no. 3]
I would like to share my codes.
From my Adapter class:
#Override
public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false);
return new CustomViewHolder(view);
}
item.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingTop="8dp"
android:paddingStart="16dp"
android:paddingEnd="16dp">
<TextView
android:id="#+id/modalityTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="#id/modalityTitle"
tools:text="X-Ray"
android:textSize="22sp"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"/>
<ImageView
android:id="#+id/statusImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="#id/modalityTextView"
app:layout_constraintBottom_toBottomOf="#id/modalityTextView"
app:layout_constraintRight_toRightOf="parent"
android:src="#drawable/ic_remove_circle_outline_black_24dp"/>
<TextView
android:id="#+id/contrastTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/modalityTextView"
app:layout_constraintLeft_toLeftOf="parent"
android:text="#string/contrast"
android:textStyle="bold"
android:layout_marginTop="4dp"/>
<TextView
android:id="#+id/contrastTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/modalityTextView"
app:layout_constraintLeft_toRightOf="#id/contrastTitle"
tools:text="Oral contrast"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"/>
<TextView
android:id="#+id/bodyPartTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/contrastTitle"
app:layout_constraintLeft_toLeftOf="parent"
android:text="#string/bodyPart"
android:textStyle="bold"
android:layout_marginTop="4dp"/>
<TextView
android:id="#+id/bodyPartTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/contrastTextView"
app:layout_constraintLeft_toRightOf="#id/bodyPartTitle"
tools:text="Chest"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"/>
<TextView
android:id="#+id/procedureTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/bodyPartTitle"
app:layout_constraintLeft_toLeftOf="parent"
android:text="#string/procedureDescription"
android:textStyle="bold"
android:layout_marginTop="4dp"/>
<TextView
android:id="#+id/procedureDescriptionTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/bodyPartTitle"
app:layout_constraintLeft_toRightOf="#id/procedureTitle"
app:layout_constraintRight_toRightOf="parent"
android:text="This is a procedure description. It will be a long text"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"/>
<TextView
android:id="#+id/checkedInAtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/procedureDescriptionTextView"
app:layout_constraintLeft_toLeftOf="parent"
android:text="#string/checked_in_at"
android:textStyle="bold"
android:layout_marginTop="4dp"/>
<TextView
android:id="#+id/checkedInAtTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/procedureDescriptionTextView"
app:layout_constraintLeft_toRightOf="#id/checkedInAtTitle"
tools:text="5:00 PM"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"/>
<View
android:layout_width="0dp"
android:layout_height="2dp"
android:background="#color/grey"
app:layout_constraintTop_toBottomOf="#id/checkedInAtTextView"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="8dp"/>
</android.support.constraint.ConstraintLayout>
DialogFragment 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="400dp"
tools:context="com.alemhealth.ticketcapture.Features.CheckInListShow.StudyListDialog.CheckInDialogFragment">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<TextView
android:id="#+id/toolbarTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/check_in_information"
android:textColor="#color/white"
android:textSize="18sp" />
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.RecyclerView
android:id="#+id/studyListRecyclerView"
android:layout_width="0dp"
android:layout_height="250dp"
app:layout_constraintTop_toBottomOf="#id/toolbar"
app:layout_constraintBottom_toTopOf="#+id/closeButton"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginBottom="16dp">
</android.support.v7.widget.RecyclerView>
<Button
android:id="#+id/closeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/studyListRecyclerView"
app:layout_constraintBottom_toBottomOf="parent"
android:background="#drawable/custom_button"
android:textColor="#color/buttonTextColor"
android:text="#string/close"
android:layout_marginBottom="8dp"/>
</android.support.constraint.ConstraintLayout>
Custom theme for DialogFragment:
<style name="DialogStyle" parent="Base.Theme.AppCompat.Dialog">
<item name="android:windowMinWidthMajor">57%</item>
<item name="android:windowMinWidthMinor">57%</item>
<item name="android:textColor">#color/text_color</item>
</style>
onCreateView of DialogFragment:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_check_in_dialog, container, false);
StudyListForDialog studyListForDialog = (StudyListForDialog) getArguments().getSerializable("data");
if(studyListForDialog!=null){
toolbarTextView.setText(studyListForDialog.getPatientName() + " - " + studyListForDialog.getPatientAge() + " - " + studyListForDialog.getPatientGender());
studyListRecyclerViewAdapter = new StudyListRecyclerViewAdapter(studyListForDialog, getActivity(), this);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
recyclerView.setAdapter(studyListRecyclerViewAdapter);
}
return view;
}
AND in this way I open my DialogFragment:
Bundle bundle = new Bundle();
bundle.putSerializable("data", data);
FragmentManager fragmentManager = ((Activity)view.getContext()).getFragmentManager();
CheckInDialogFragment checkInDialogFragment = new CheckInDialogFragment();
checkInDialogFragment.setStyle(DialogFragment.STYLE_NORMAL, R.style.DialogStyle);
checkInDialogFragment.setArguments(bundle);
checkInDialogFragment.show(fragmentManager, "check-in");
Please help me fix this weird problem.
May be it's a bug of ConstaintLayout.
I updated my DialogFragment XML root with LinearLayout instead of ConstraintLayout. And it solved the shrinking problem.
My updated DialogFragment xml is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary">
<TextView
android:id="#+id/toolbarTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/check_in_information"
android:textColor="#color/white"
android:textSize="18sp" />
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.RecyclerView
android:id="#+id/studyListRecyclerView"
android:layout_width="match_parent"
android:layout_height="250dp"
app:layout_constraintTop_toBottomOf="#id/toolbar"
app:layout_constraintBottom_toTopOf="#+id/closeButton"
android:layout_marginBottom="16dp">
</android.support.v7.widget.RecyclerView>
<Button
android:id="#+id/closeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/custom_button"
android:textColor="#color/buttonTextColor"
android:text="#string/close"
android:layout_marginBottom="8dp"
android:layout_gravity="center"/>
</LinearLayout>