I have a recyclerview whose items look like this:
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_food_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginBottom="4dp"
app:cardCornerRadius="4dp">
<LinearLayout
android:id="#+id/linear_food_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="start"
android:orientation="horizontal"
android:padding="4dp">
<com.mikhaellopez.circleview.CircleView
android:id="#+id/food_image"
android:layout_width="80dp"
android:layout_height="80dp"
app:cv_color="#color/colorAccent" />
<LinearLayout
android:id="#+id/food_contents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:orientation="vertical">
<TextView
android:id="#+id/food_title_homepage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:fontFamily="#font/sans_regular"
android:text="عنوان غذا"
android:textAppearance="#style/TextAppearance.AppCompat.Title" />
<TextView
android:id="#+id/ingredients_homepage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:fontFamily="#font/sans_regular"
android:text="مواد اولیه"
android:textAppearance="#style/TextAppearance.MaterialComponents.Subtitle1" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
I'm trying to convert this into a flat hierarchy using Constraintlayout.
Here's how it looks:
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_food_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginBottom="4dp"
app:cardCornerRadius="4dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/linear_food_item"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/food_title_homepage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="8dp"
android:text="عنوان غذا"
android:textAppearance="#style/TextAppearance.AppCompat.Title"
app:layout_constraintStart_toEndOf="#+id/food_image"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/ingredients_homepage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text="مواد اولیه"
android:textAppearance="#style/TextAppearance.MaterialComponents.Subtitle1"
app:layout_constraintStart_toEndOf="#+id/food_image"
app:layout_constraintTop_toBottomOf="#+id/food_title_homepage" />
<com.mikhaellopez.circleview.CircleView
android:id="#+id/food_image"
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
app:cv_color="#color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
Here's where my Recyclerview is inserted:
<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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".main.homepage.HomepageFragment">
<ProgressBar
android:id="#+id/homepage_progressbar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recipes"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:scrollbars="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/homepage_toolbar"
tools:listitem="#layout/fragment_homepage_food_item" />
<include
android:id="#+id/homepage_toolbar"
layout="#layout/fragment_homepage_toolbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Here's how each item should be: https://i.stack.imgur.com/AcfAm.png
But I don't get the same results in the Recyclerview: https://i.stack.imgur.com/jpUG4.png
I didn't have the problem before I converted the view into Constraintlayout!! Everything was working just fine until now that I converted them. They all become left-aligned in the Recyclerview!!
Does anyone know what the problem is?? Thanks in advance
-- Updated --
How it looks like on an android emulator or any other devices: https://i.stack.imgur.com/tvGz4.png
When I scroll down to the bottom (I update the list after each scroll) some items become right-aligned (they somehow get fixed) but the rest stays the same (still left aligned)
-- Java Code --
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
viewModel = new ViewModelProvider(this).get(HomepageViewModel.class);
getData(0);
setRecyclerView(linearLayoutManager);
EndlessRecyclerViewScrollListener scrollListener = new EndlessRecyclerViewScrollListener(linearLayoutManager) {
#Override
public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
getData(page);
}
};
recyclerView.addOnScrollListener(scrollListener);
private void getData(int offset) {
viewModel.init(this, offset);
viewModel.getFoodsLiveData().observe(getViewLifecycleOwner(), foodList -> {
if (foodList != null) {
foods.addAll(foodList);
foodList.clear();
foodAdapter.notifyDataSetChanged();
}
});
}
private void setRecyclerView(LinearLayoutManager linearLayoutManager) {
foodAdapter = new FoodAdapter(foods);
recyclerView.setAdapter(foodAdapter);
recyclerView.setLayoutManager(linearLayoutManager);
}
My adapter:
private void getData(int offset) {
viewModel.init(this, offset);
viewModel.getFoodsLiveData().observe(getViewLifecycleOwner(), foodList -> {
if (foodList != null) {
foods.addAll(foodList);
foodList.clear();
foodAdapter.notifyDataSetChanged();
}
});
}
private void setRecyclerView(LinearLayoutManager linearLayoutManager) {
foodAdapter = new FoodAdapter(foods);
recyclerView.setAdapter(foodAdapter);
recyclerView.setLayoutManager(linearLayoutManager);
}
My adapter:
private List<Food> foods;
FoodAdapter(List<Food> foods) {
this.foods = foods;
}
static class FoodViewHolder extends RecyclerView.ViewHolder {
CircleView foodImage;
TextView foodTitle, ingredients;
CardView foodItem;
FoodViewHolder(View itemView) {
super(itemView);
foodImage = itemView.findViewById(R.id.food_image);
foodTitle = itemView.findViewById(R.id.food_title_homepage);
ingredients = itemView.findViewById(R.id.ingredients_homepage);
foodItem = itemView.findViewById(R.id.card_food_item);
}
}
#NonNull
#Override
public FoodViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_homepage_food_item, parent, false);
return new FoodViewHolder(v);
}
#Override
public void onBindViewHolder(#NonNull FoodViewHolder holder, int position) {
final Food currentFood = foods.get(position);
StringBuilder food_ingredient_str = new StringBuilder();
int ingredient_position = 0;
int ingredients_size = currentFood.getFood_ingredients().size();
for (Food.FoodIngredient foodIngredient : currentFood.getFood_ingredients()) {
food_ingredient_str.append(foodIngredient.getIngredient());
if (ingredient_position != ingredients_size / 3)
food_ingredient_str.append(", ");
if (ingredient_position == ingredients_size / 3) {
food_ingredient_str.append(" و ...");
break;
}
ingredient_position += 1;
}
holder.foodTitle.setText(currentFood.getName());
holder.ingredients.setText(food_ingredient_str);
holder.foodItem.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Bundle bundle = new Bundle();
bundle.putSerializable("current_food", currentFood);
Navigation.findNavController(v).navigate(R.id.action_navigation_home_to_navigation_food, bundle);
}
});
}
#Override
public int getItemCount() {
return foods.size();
}
If you want to create a list using recyclerview and each item to be right aligned as in Arabic.. then try these approaches
replace your "recycle_view_item_layout.xml" with this
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_food_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginBottom="4dp"
app:cardCornerRadius="4dp">
<LinearLayout
android:id="#+id/linear_food_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="4dp">
<LinearLayout
android:id="#+id/food_contents"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/food_title_homepage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:ellipsize="start"
android:fontFamily="#font/sans_regular"
android:singleLine="true"
android:text="عنوان غذا"
android:textAppearance="#style/TextAppearance.AppCompat.Title" />
<TextView
android:id="#+id/ingredients_homepage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:ellipsize="start"
android:fontFamily="#font/sans_regular"
android:singleLine="true"
android:text="مواد اولیه"
android:textAppearance="#style/TextAppearance.MaterialComponents.Subtitle1" />
</LinearLayout>
<com.mikhaellopez.circleview.CircleView
android:id="#+id/food_image"
android:layout_width="80dp"
android:layout_height="80dp"
app:cv_color="#color/colorAccent" />
</LinearLayout>
</androidx.cardview.widget.CardView>
replace your "recycle view" with this
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recipes"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#id/homepage_toolbar"
tools:listitem="#layout/fragment_homepage_food_item" />
and attach a layout manager like this (important)
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
setRecyclerView(layoutManager);
and rest of your code seems okay
Related
I believe TableRow from activity_main and TableRow from recycler_item_header_row have the same values of fields. But they are not aligned! They are shown like this:
enter image description here
enter image description here
Why the positions of textViews in rows from the activity_main and from the RecyclerView aren’t aligned?
activity_main structure:
<TableLayout>
<TableRow ><\TableRow>
<RecyclerView> <\RecyclerView>
<\Table Layout>
activity_main:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout 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"
tools:context=".MainActivity">
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<TextView
android:layout_column="0"
android:layout_gravity="center"
android:layout_weight="0.3"
android:width="0dp"
android:gravity="center"
android:text="ID"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:layout_column="1"
android:layout_gravity="center"
android:layout_weight="0.4"
android:width="0dp"
android:gravity="center"
android:text="Name"
android:textSize="16dp"
android:textStyle="bold" />
<TextView
android:layout_column="2"
android:layout_gravity="center"
android:layout_weight="0.3"
android:width="0dp"
android:gravity="center"
android:text="Payment"
android:textSize="16dp"
android:textStyle="bold" />
</TableRow>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</androidx.recyclerview.widget.RecyclerView>
</TableLayout>
Two types of item for Recycler View:
recycler_item_header_row:
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<TextView
android:layout_column="0"
android:layout_gravity="center"
android:layout_weight="0.3"
android:width="0dp"
android:gravity="center"
android:text="ID"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:layout_column="1"
android:layout_gravity="center"
android:layout_weight="0.4"
android:width="0dp"
android:gravity="center"
android:text="Name"
android:textSize="16dp"
android:textStyle="bold" />
<TextView
android:layout_column="2"
android:layout_gravity="center"
android:layout_weight="0.3"
android:width="0dp"
android:gravity="center"
android:text="Payment"
android:textSize="16dp"
android:textStyle="bold" />
</TableRow>
recycler_item_regular_row:
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
>
<TextView
android:id="#+id/recycler_item_regular_cell_ID"
android:layout_column="0"
android:layout_weight="0.3"
android:width="0dp"
android:gravity="center"
android:text="ID"
android:textSize="16dp" />
<TextView
android:id="#+id/cell_name"
android:layout_column="1"
android:layout_weight="0.4"
android:width="0dp"
android:gravity="center"
android:text="Name"
android:textSize="16dp" />
<TextView
android:id="#+id/cell_payment"
android:layout_column="2"
android:layout_weight="0.3"
android:width="0dp"
android:gravity="center"
android:text="Payment"
android:textSize="16dp" />
</TableRow>
MainActivity
public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private ArrayList<PaymentModel> paymentData;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
paymentData = new ArrayList<>();
add10TestItems(paymentData);
recyclerView = findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
RecyclerViewAdapter adapter = new RecyclerViewAdapter(this, paymentData);
recyclerView.setAdapter(adapter);
}
private void add10TestItems(ArrayList<PaymentModel> paymentData) {
for (int i = 0; i < 10; i++) {
paymentData.add(new PaymentModel("A" + i, "Name",
String.valueOf(5 * i)));
}
paymentData.add(new PaymentModel("IDDDDDDDDDDDDDDDDDD", "dddddddddddddddd", "dsfdfdf"));
paymentData.add(new PaymentModel("ID", "Name", "Payment"));
}
}
Adapter:
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public static final int HEADER_ROW_TYPE = 0;
public static final int REGULAR_ROW_TYPE = 1;
private Context context;
private List<PaymentModel> paymentModelList;
public RecyclerViewAdapter(Context context, List<PaymentModel> paymentModelList) {
this.context = context;
this.paymentModelList = paymentModelList;
}
#Override
public int getItemViewType(int position) {
if (0 == position) {
return HEADER_ROW_TYPE;
} else {
return REGULAR_ROW_TYPE;
}
}
#NonNull
#Override
public RecyclerView.ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view;
RecyclerView.ViewHolder viewHolder;
if (viewType == HEADER_ROW_TYPE) {
view = LayoutInflater.from(context).inflate(R.layout.recycler_item_header_row,
parent, false);
viewHolder = new ViewHolderHeaderRow(view);
} else {
view = LayoutInflater.from(context).inflate(R.layout.recycler_item_regular_row,
parent, false);
viewHolder = new ViewHolderRegularRow(view);
}
return viewHolder;
}
#Override
public void onBindViewHolder(#NonNull RecyclerView.ViewHolder holder, int position) {
if (position == 0) {
ViewHolderHeaderRow headerAdapter = (ViewHolderHeaderRow) holder;
} else {
ViewHolderRegularRow regularAdapter = (ViewHolderRegularRow) holder;
regularAdapter.setData(paymentModelList.get(position - 1));
}
}
#Override
public int getItemCount() {
return (paymentModelList.size() + 1);
}
public class ViewHolderRegularRow extends RecyclerView.ViewHolder {
private TextView cellID;
private TextView cellName;
private TextView cellPayment;
public ViewHolderRegularRow(#NonNull View itemView) {
super(itemView);
cellID = itemView.findViewById(R.id.recycler_item_regular_cell_ID);
cellName = itemView.findViewById(R.id.cell_name);
cellPayment = itemView.findViewById(R.id.cell_payment);
}
public void setData(PaymentModel paymentModel) {
cellID.setText(paymentModel.getId());
cellName.setText(paymentModel.getName());
cellPayment.setText(paymentModel.getPayment());
}
}
public class ViewHolderHeaderRow extends RecyclerView.ViewHolder {
public ViewHolderHeaderRow(#NonNull View itemView) {
super(itemView);
}
}
}
Model:
public class PaymentModel {
private String id;
private String name;
private String payment;
public PaymentModel(String id, String name, String payment) {
this.id = id;
this.name = name;
this.payment = payment;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getPayment() {
return payment;
}
}
I would not use TableLayout and TableRow as TableLayout extra logic to resize any child that is a TableRow BUT as you only have one TableRow as a child of the TableLayout that logic is redundant and is less efficient.
The TableRow's that are inside the RecyclerView are the children of the RecyclerView not children of the TableLayout and as the Docs says
If a TableRow's parent is not a TableLayout, the TableRow will behave as an horizontal LinearLayout
And thus won't do any of their normal resizing of the table columns
So in practice you have actually got a structure like:-
<TableLayout>
<TableRow ><\TableRow>
<\TableLayout>
<RecyclerView>
<\LinearLayout>
<\LinearLayout>
.....
<\RecyclerView>
So as the layout weights are based on content and how much each is allowed to grow if need to, the long content RecyclerView rows grow the size of the long content cells differently to the items in the unrelated TableLayout Rows which don't need to grow.
I've designed a similar type layout but used a ConstraintLayout with a layout_constraintWidth_percent value to achieve wider Name column you are trying to achieve with the weights. This works as this is based on the percentage of the fixed width of the parent NOT the variable width of the content and thus the items in the RecyclerView behave the same are the Header line as they both have the same parent size.
Below are the new layout files need
activity_main
<?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"
tools:context=".MainActivity">
<TextView
android:id="#+id/HeaderID"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="ID"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="#+id/HeaderName"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.3"/>
<TextView
android:id="#+id/HeaderName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Name"
android:textSize="16dp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="#+id/HeaderID"
app:layout_constraintEnd_toStartOf="#+id/HeaderPayment"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="#+id/HeaderID"
app:layout_constraintWidth_percent="0.4"/>
<TextView
android:id="#+id/HeaderPayment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Payment"
android:textSize="16dp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="#+id/HeaderName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="#+id/HeaderID"
app:layout_constraintWidth_percent="0.3"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/HeaderID"/>
</androidx.constraintlayout.widget.ConstraintLayout>
recycler_item_header_row
<?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="wrap_content">
<TextView
android:id="#+id/HeaderRowID"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="ID"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="#+id/HeaderRowName"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.3"/>
<TextView
android:id="#+id/HeaderRowName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Name"
android:textSize="16dp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="#+id/HeaderRowID"
app:layout_constraintEnd_toStartOf="#+id/HeaderRowPayment"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="#+id/HeaderRowID"
app:layout_constraintWidth_percent="0.4"/>
<TextView
android:id="#+id/HeaderRowPayment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Payment"
android:textSize="16dp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="#+id/HeaderRowName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="#+id/HeaderRowID"
app:layout_constraintWidth_percent="0.3"/>
</androidx.constraintlayout.widget.ConstraintLayout>
recycler_item_regular_row
<?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="wrap_content">
<TextView
android:id="#+id/recycler_item_regular_cell_ID"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="16dp"
app:layout_constraintEnd_toStartOf="#+id/cell_name"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.3"
tools:text="ID" />
<TextView
android:id="#+id/cell_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="16dp"
app:layout_constraintStart_toEndOf="#+id/recycler_item_regular_cell_ID"
app:layout_constraintEnd_toStartOf="#+id/cell_payment"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="#+id/recycler_item_regular_cell_ID"
app:layout_constraintWidth_percent="0.4"
tools:text="Name" />
<TextView
android:id="#+id/cell_payment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="16dp"
app:layout_constraintBottom_toBottomOf="#+id/recycler_item_regular_cell_ID"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/cell_name"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.3"
tools:text="Payment" />
</androidx.constraintlayout.widget.ConstraintLayout>
This produces the following result with all the columns lined up.
i have created firebase recyclerview inside nestedscrollview in fragment.it works well.but when i use updateoptions in firebase recyclerview,the recyclerview not working.
I dont know how to resolve this problem.
initially the fragment created it loaded with items from firebase.the recyclerview not work when i click the button to updateoptions
this is my firebaserecyclerview
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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/fragment_bg"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:orientation="vertical"
android:layout_marginBottom="50dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/montserrat"
android:text="Hi, Aashik"
android:textColor="#color/colorPrimary"
android:layout_marginHorizontal="20dp"
android:textSize="25dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/montserrat_bold"
android:layout_marginHorizontal="20dp"
android:text="Welcome Back"
android:textColor="#color/colorPrimary"
android:textSize="30dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:fontFamily="#font/montserrat_bold"
android:text="Category"
android:textColor="#color/colorPrimaryDark"
android:textSize="20sp" />
<Button
android:id="#+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/montserrat_bold"
android:text="Products"
android:layout_marginVertical="10dp"
android:layout_marginHorizontal="20dp"
android:textColor="#color/colorPrimaryDark"
android:textSize="20sp" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/productsRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="100dp"
android:layoutAnimation="#anim/layoutanimation"
/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
and the code is
productsRef = FirebaseDatabase.getInstance().getReference().child("products");
recyclerView = (RecyclerView) root.findViewById(R.id.productsRecyclerView);
btn= (Button) root.findViewById(R.id.btn);
layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);
recyclerView.setHasFixedSize(true);
FirebaseRecyclerOptions<Products> options=
new FirebaseRecyclerOptions.Builder<Products>()
.setQuery(productsRef, Products.class)
.build();
adapter = new FirebaseRecyclerAdapter<Products, ProductViewHolder>(options) {
#Override
protected void onBindViewHolder(#NonNull final ProductViewHolder holder, final int position, #NonNull final Products model) {
holder.productNameTv.setText(model.getName());
Picasso.get().load(model.getImageurl()).fit().into(holder.productImageIv);
holder.cardcontainer.setAnimation(AnimationUtils.loadAnimation(getActivity(),R.anim.cardviewanimation));
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), ProductDetailsActivity.class);
intent.putExtra("imageurl",model.getImageurl());
intent.putExtra("name",model.getName());
intent.putExtra("desc",model.getDesc());
intent.putExtra("mrp",model.getMrp());
intent.putExtra("availability",model.getAvailability());
intent.putExtra("pid",model.getPid());
startActivity(intent);
}
});
}
#NonNull
#Override
public ProductViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.product_items_layout, parent, false);
ProductViewHolder holder = new ProductViewHolder(view);
return holder;
}
};
recyclerView.setAdapter(adapter);
adapter.startListening();
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Query query = productsRef.orderByChild("category").equalTo(catName);
FirebaseRecyclerOptions<Products> newOptions=
new FirebaseRecyclerOptions.Builder<Products>()
.setQuery(query, Products.class)
.build();
adapter.updateOptions(newOptions);
);
recylerview layout is
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_marginVertical="10dp"
app:cardCornerRadius="2dp"
app:cardElevation="5dp"
android:layout_marginHorizontal="20dp"
android:id="#+id/cardcontainer"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<ImageView
android:id="#+id/productImageIv"
android:layout_width="100dp"
android:layout_height="match_parent"
android:src="#drawable/ic_topsym"
android:layout_margin="10dp"
>
</ImageView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="#+id/productNameTv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="20sp"
android:text="#string/welcome"
android:textColor="#color/colorBlack"
android:fontFamily="#font/arimo_bold"
android:padding="20dp">
</TextView>
</RelativeLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
Thank in advance.
Please use swipe to refresh component or use notifiedDatasetChanged() in your adapter
I am using CardStackView library but I also want to scroll its item and the only swap left and right
public class CardFragment extends Fragment implements CardStackListener {
private View view;
FragmentCardBinding binding;
CardStackLayoutManager manager;
CardStackAdapter cardStackAdapter;
private List<CardModel> listCard = new ArrayList<CardModel>();
public static MyAppAdapter myAppAdapter;
public static ViewHolder viewHolder;
private ArrayList<Data> array;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
binding = DataBindingUtil.inflate(
inflater, R.layout.fragment_card, container, false);
manager = new CardStackLayoutManager(getContext());
listCard.add(new CardModel("MaryBurgess", "steattle, USA", "USA", R.drawable.imggirl));
listCard.add(new CardModel("MaryBurgess", "steattle, USA", "USA", R.drawable.imggirl));
listCard.add(new CardModel("MaryBurgess", "steattle, USA", "USA", R.drawable.imggirl));
listCard.add(new CardModel("MaryBurgess", "steattle, USA", "USA", R.drawable.imggirl));
manager.setStackFrom(StackFrom.None);
manager.setVisibleCount(3);
manager.setTranslationInterval(8.0f);
manager.setScaleInterval(0.95f);
manager.setSwipeThreshold(0.3f);
manager.setMaxDegree(20.0f);
manager.setDirections(Direction.HORIZONTAL);
manager.setCanScrollHorizontal(true);
manager.setCanScrollVertical(true);
binding.cardStackView.setLayoutManager(manager);
cardStackAdapter = new CardStackAdapter(listCard, getActivity());
binding.cardStackView.setAdapter(cardStackAdapter);
binding.imgFilter.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getContext(), LookingFor.class);
startActivity(intent);
getActivity().finish();
}
});
myAppAdapter = new MyAppAdapter(listCard, getContext());
return view = binding.getRoot();
}
#Override
public void onCardDragging(Direction direction, float ratio) {
}
#Override
public void onCardSwiped(Direction direction) {
Log.d("CardStackView", String.valueOf(direction));
}
#Override
public void onCardRewound() {
}
#Override
public void onCardCanceled() {
}
here is adapter class
public class CardStackAdapter extends RecyclerView.Adapter<CardStackAdapter.ViewHolder> {
private List<CardModel> listCard = new ArrayList<CardModel>();
private Context c;
public CardStackAdapter(List<CardModel> listCard,Context c ) {
this.listCard = listCard;
this.c = c;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_item, parent, false);
ViewHolder vh = new ViewHolder(v);
return vh;
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
holder.username.setText(listCard.get(position).getName());
holder.cityName.setText(listCard.get(position).getCity());
Glide.with(holder.item_image)
.load(listCard.get(position).getUserImage())
.into(holder.item_image);
}
#Override
public int getItemCount() {
return listCard.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView username, cityName;
RoundedImageView item_image;
public ViewHolder(#NonNull View itemView) {
super(itemView);
username = itemView.findViewById(R.id.user_name);
cityName = itemView.findViewById(R.id.city_name);
item_image = itemView.findViewById(R.id.item_image);
}
}
}
and adapter XML :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="#+id/ll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
android:foreground="?attr/selectableItemBackground"
app:cardBackgroundColor="#android:color/white"
app:cardCornerRadius="8dp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true">
<com.makeramen.roundedimageview.RoundedImageView
android:id="#+id/item_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/imggirl"
app:riv_corner_radius="8dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="20dp"
android:orientation="vertical"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.bugfreecode.anotherchanz.fonts.GothamBookBold
android:id="#+id/user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MaryBurgess"
android:textColor="#android:color/white"
android:textSize="26sp"
android:textStyle="bold" />
<ImageView
android:layout_width="18dp"
android:layout_height="18dp"
android:src="#drawable/verified" />
</LinearLayout>
<TextView
android:id="#+id/city_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Steattle, USA"
android:textColor="#android:color/white"
android:textSize="16dp"
android:textStyle="bold" />
</LinearLayout>
<FrameLayout
android:id="#+id/left_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center"
android:src="#drawable/dislike" />
<FrameLayout
android:id="#+id/bottom_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</FrameLayout>
<FrameLayout
android:id="#+id/right_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center"
android:src="#drawable/like" />
</FrameLayout>
<FrameLayout
android:id="#+id/top_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<LinearLayout
android:id="#+id/lytChips"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="20dp"
android:layout_marginRight="15dp"
android:orientation="vertical">
<com.google.android.material.chip.ChipGroup
android:id="#+id/choice_chip_group"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.chip.Chip
card_view:iconStartPadding="10dp"
card_view:chipIconSize="15dp"
android:drawablePadding="5dp"
android:id="#+id/choice_chip5"
android:textColor="#color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Architecture/Interior design"
android:textAppearance="#style/AppTheme.GenderChip"
android:theme="#style/Theme.MaterialComponents.Light"
app:chipStartPadding="8dp"
app:chipStrokeWidth="1dp" />
</com.google.android.material.chip.ChipGroup>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
fragment XML
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#drawable/gradiant_back">
<com.bugfreecode.anotherchanz.fonts.GothamBookBold
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="30dp"
android:gravity="center"
android:letterSpacing="0.23"
android:singleLine="true"
android:text="Anotherchanz"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="23sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imgFilter"
android:layout_marginEnd="20dp"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_gravity="center"
android:layout_marginStart="20dp"
android:src="#drawable/ic_filler" />
</LinearLayout>
<LinearLayout
android:background="#drawable/back_full"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- <com.lorentzos.flingswipe.SwipeFlingAdapterView
android:id="#+id/flingContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradiant_back"
app:rotation_degrees="15.5" />-->
<com.yuyakaido.android.cardstackview.CardStackView
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:id="#+id/card_stack_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.yuyakaido.android.cardstackview.CardStackView>
</LinearLayout>
</LinearLayout>
Card swap is working perfectly but I want to make card scroll vertically also I have used scroll view in adapter items but it is not working its only working for swap, please help me I would appreciate every answer.
I have made a recyclerView which is inside a fragment. It has an ImageView in each item and the image is loaded with Picasso from a url. But the problem is that the recyclerView lags when i scroll for the first time, but when the data is loaded, it scrolls normally. I tried to remove all the operations in the onBindViewHolder but the problem still persists. I then removed the complex part of the item layout but still no improvements. I am running on Snapdragon 845 so there is no issue with the phone's performance, I tried the same with other devices and it lags. I even tried with hardware acceleration, but it didn't help.
Here is my Adapter:
public class MovieAdapter extends RecyclerView.Adapter<MovieAdapter.MovieHolder> {
private List<Movie> mMovies;
private Context mContext;
public MovieAdapter(Context mContext, List<Movie> mMovies) {
this.mContext = mContext;
this.mMovies = mMovies;
}
#NonNull
#Override
public MovieHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(mContext).inflate(R.layout.item_movie_movie_layout, viewGroup, false);
return new MovieHolder(view);
}
#Override
public void onBindViewHolder(#NonNull MovieHolder movieHolder, int i) {
Movie movie = mMovies.get(i);
if (movie.getTitle2().equals("")) {
movieHolder.mTextViewTitle1.setText(movie.getTitle1());
movieHolder.mTextViewTitle2.setVisibility(View.GONE);
} else {
movieHolder.mTextViewTitle1.setText(movie.getTitle1());
movieHolder.mTextViewTitle2.setVisibility(View.VISIBLE);
movieHolder.mTextViewTitle2.setText(movie.getTitle2());
}
movieHolder.mTextViewGenre.setText(movie.getGenre());
movieHolder.mRatingBar.setRating((float) 4.5);
String url = "https://image.tmdb.org/t/p/w342";
url += movie.getPoster_path();
Transformation transformation = new Rounded(8, ALL);
Picasso.get().load(url)
.placeholder(R.color.colorAccent)
.transform(transformation)
.resize(100, 150)
.centerCrop()
.into(movieHolder.mImageViewPoster);
}
#Override
public int getItemCount() {
return mMovies.size();
}
public class MovieHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private ImageView mImageViewPoster;
private TextView mTextViewTitle1;
private TextView mTextViewTitle2;
private TextView mTextViewGenre;
private RatingBar mRatingBar;
public MovieHolder(#NonNull View itemView) {
super(itemView);
mImageViewPoster = itemView.findViewById(R.id.image_view_poster);
mTextViewTitle1 = itemView.findViewById(R.id.text_view_title_1);
mTextViewTitle2 = itemView.findViewById(R.id.text_view_title_2);
mTextViewGenre = itemView.findViewById(R.id.text_view_genre);
mRatingBar = itemView.findViewById(R.id.rating_bar);
itemView.setOnClickListener(this);
}
#Override
public void onClick(View v) {
Movie movie = mMovies.get(getAdapterPosition());
Intent intent = new Intent(mContext, MovieActivity.class);
intent.putExtra("EXTRA", movie);
mContext.startActivity(intent);
}
}
}
Here is my item layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="192dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.v7.widget.CardView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="132dp"
android:layout_marginStart="28dp"
android:layout_marginEnd="28dp"
android:layout_marginBottom="8dp"
android:elevation="0dp"
app:cardBackgroundColor="#color/colorAccent"
app:cardCornerRadius="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
</android.support.v7.widget.CardView>
<ImageView
android:id="#+id/image_view_poster"
android:layout_width="100dp"
android:layout_height="150dp"
android:layout_marginStart="12dp"
android:layout_marginBottom="12dp"
android:adjustViewBounds="true"
android:elevation="16dp"
app:layout_constraintBottom_toBottomOf="#+id/imageView"
app:layout_constraintStart_toStartOf="#+id/imageView" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="12dp"
android:elevation="8dp"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingLeft="8dp"
app:layout_constraintBottom_toBottomOf="#+id/imageView"
app:layout_constraintEnd_toEndOf="#+id/imageView"
app:layout_constraintStart_toEndOf="#+id/image_view_poster"
app:layout_constraintTop_toTopOf="#+id/imageView">
<TextView
android:id="#+id/text_view_title_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:includeFontPadding="false"
android:maxLines="1"
android:text="Skyscraper"
android:textSize="16dp" />
<TextView
android:id="#+id/text_view_title_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="0.3"
android:ellipsize="end"
android:includeFontPadding="false"
android:maxLines="1"
android:text="Skyscraper"
android:textSize="12dp" />
<Space
android:layout_width="0dp"
android:layout_height="8dp" />
<android.support.v7.widget.AppCompatRatingBar
android:id="#+id/rating_bar"
style="#style/Base.Widget.AppCompat.RatingBar.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="true"
android:numStars="5"
android:outlineProvider="paddedBounds"
android:progressBackgroundTint="#FFFFFF"
android:progressTint="#FECE00"
android:stepSize="0.5" />
<Space
android:layout_width="0dp"
android:layout_height="8dp" />
<TextView
android:id="#+id/text_view_genre"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:text="Action | Adventure"
android:textSize="12dp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
I'm using a NestedScrollView in a CardView that's generated in a RecyclerView. I can't get the scrolling to work - there seems to be sporadic moments when I can scroll through the list in the top item but no other scrolls seem to work. Cheers!
This is the layout of the cardView that's generated in the RecyclerView:
<?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:id="#+id/checkout_relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/merchantPurchase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginLeft="12dp"
android:layout_marginTop="4dp"
android:text="TextView"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="#+id/checkoutCard"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
android:layout_marginStart="12dp" />
<android.support.v7.widget.CardView
android:id="#+id/checkoutCard"
android:layout_width="340dp"
android:layout_height="90dp"
android:layout_margin="5dp"
android:layout_marginBottom="11dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:elevation="5dp"
app:cardCornerRadius="5dp"
app:contentPadding="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_goneMarginLeft="5dp"
app:layout_goneMarginRight="5dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingRight="5dp">
<TextView
android:id="#+id/textCentre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:text="Test2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.7"
app:layout_constraintLeft_toLeftOf="#+id/extraContainer"
app:layout_constraintRight_toRightOf="#+id/extraContainer" />
<TextView
android:id="#+id/textRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:text="Test3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.533"
app:layout_constraintLeft_toLeftOf="#+id/otherContainer"
app:layout_constraintRight_toRightOf="#+id/otherContainer" />
<TextView
android:id="#+id/textLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:text="Test1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.444"
app:layout_constraintLeft_toLeftOf="#+id/priceContainer"
app:layout_constraintRight_toRightOf="#+id/priceContainer" />
<TextView
android:id="#+id/extraContainer"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:adjustViewBounds="true"
android:clickable="true"
android:scaleType="centerCrop"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="#+id/priceContainer"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.17" />
<TextView
android:id="#+id/priceContainer"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
android:adjustViewBounds="true"
android:clickable="true"
android:scaleType="centerCrop"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="#+id/itemTitle"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.17" />
<TextView
android:id="#+id/otherContainer"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:adjustViewBounds="true"
android:clickable="true"
android:scaleType="centerCrop"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="#+id/extraContainer"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.17" />
<TextView
android:id="#+id/itemTitle"
android:layout_width="71dp"
android:layout_height="39dp"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
android:text="TextView"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.512" />
<LinearLayout
android:layout_width="63dp"
android:layout_height="53dp"
android:layout_marginLeft="0dp"
android:orientation="vertical"
app:layout_constraintLeft_toRightOf="#+id/otherContainer"
tools:layout_editor_absoluteY="19dp"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteX="258dp">
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:layout_gravity="fill_vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView45"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView44"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView43"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
Then, my abridged code for MainActivity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.checkout_home);
cardPurchasesDataSet = new ArrayList<>();
for (int i = 0; i < productsForPurchase.length; i++) {
cardPurchasesDataSet.add(productsForPurchase[i]);
}
card_totalPrice = new ArrayList<>();
for (int i = 0; i < totalPriceData.length; i++) {
card_totalPrice.add(totalPriceData[i]);
}
card_extras = new ArrayList<>();
for (int i = 0; i < extrasData.length; i++) {
card_extras.add(extrasData[i]);
}
card_more = new ArrayList<>();
for (int i = 0; i < moreData.length; i++) {
card_more.add(moreData[i]);
}
merchants = new ArrayList<>();
for (int i = 0; i < merchantsData.length; i++) {
merchants.add(merchantsData[i]);
}
card_recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
card_layoutManger = new LinearLayoutManager(this);
card_recyclerView.setLayoutManager(card_layoutManger);
card_adapter = new checkout_card_Adapter(cardPurchasesDataSet, card_totalPrice, card_extras, card_more, merchants);
card_recyclerView.setAdapter(card_adapter);
}
UPDATE 01: Added mainActivity layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="368dp"
android:layout_height="551dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:overScrollMode="never"
android:layout_marginBottom="8dp" />
Adapter
public class Checkout_Card_Adapter extends
RecyclerView.Adapter<Checkout_Card_Adapter.ViewHolder>{
private ArrayList<String> titleOfPurchase;
private ArrayList<String> priceOfPurchase;
private ArrayList<String> extrasOfPurchase;
private ArrayList<String> moreOfPurchase;
private ArrayList<String> merchantOfPurchase;
public Checkout_Card_Adapter(ArrayList<String> titleOfPurchase, ArrayList<String> priceOfPurchase, ArrayList<String> extrasOfPurchase, ArrayList<String> moreOfPurchase, ArrayList<String> merchantOfPurchase) {
this.titleOfPurchase = titleOfPurchase;
this.priceOfPurchase = priceOfPurchase;
this.extrasOfPurchase = extrasOfPurchase;
this.moreOfPurchase = moreOfPurchase;
this.merchantOfPurchase = merchantOfPurchase;
}
public interface VenueAdapterInterface {
void onVenueButtonClick(int position);
}
#Override
public Checkout_Card_Adapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.checkout_scrollable_card, viewGroup, false);
Checkout_Card_Adapter.ViewHolder viewHolder = new Checkout_Card_Adapter.ViewHolder(v);
return viewHolder;
}
#Override
public void onBindViewHolder(Checkout_Card_Adapter.ViewHolder viewHolder, final int position) {
viewHolder.itemTitle.setText(titleOfPurchase.get(position));
viewHolder.itemPrice.setText(priceOfPurchase.get(position));
viewHolder.itemExtras.setText(extrasOfPurchase.get(position));
viewHolder.itemMore.setText(moreOfPurchase.get(position));
viewHolder.merchant.setText(merchantOfPurchase.get(position));
}
#Override
public int getItemCount() {
return titleOfPurchase.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public ImageButton itemImage;
public TextView itemTitle;
public TextView itemPrice;
public TextView itemExtras;
public TextView itemMore;
public TextView merchant;
public ViewHolder(final View itemView) {
super(itemView);
itemTitle = (TextView) itemView.findViewById(R.id.itemTitle);
itemPrice = (TextView) itemView.findViewById(R.id.priceContainer);
itemExtras = (TextView) itemView.findViewById(R.id.extraContainer);
itemMore = (TextView) itemView.findViewById(R.id.otherContainer);
merchant = (TextView) itemView.findViewById(R.id.merchantPurchase);
}
}
}
As per your screen shot how do you expect it to scroll the inner view while it showing all the views? it will only scroll on small devices where your all textview won't be able to display. Can you please post a proper screenshot of this view from app.