Android Fragment RecyclerView Transparent when replace - android

i just want to replace a fragment by using this code:
fragmentManager.beginTransaction()
.replace(R.id.homepage_fragment_menu, fragment)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit();
the fragment has recyclerview. but when i see the result of fragment, there's no shown of recyclerview. but when i checked in LayoutInspector, it's showed, but invisible like
this
And here's the code when set the adapter on RecyclerView
bookingHistoryProgressBar.setVisibility(View.GONE);
bookingHistoryList.setVisibility(View.VISIBLE);
adapterBookingHistoryList = new AdapterBookingHistoryList(this, bookingHistoryListModels);
bookingHistoryList.setAdapter(adapterBookingHistoryList);
Here's the layout code for RecyclerView and Adapter
XML Fragment Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/grey"
tools:context=".home.bookinghistorypage.BookingHistoryFragment"
android:gravity="center">
<android.support.v7.widget.RecyclerView
android:id="#+id/bookingHistory_listBooking"
android:background="#color/white_3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
Adapter
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/booking_history_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="6dp"
app:cardElevation="6dp"
android:layout_marginTop="#dimen/margin_small"
android:layout_marginBottom="#dimen/margin_small"
app:cardUseCompatPadding="true">
<LinearLayout
android:background="#color/white"
android:paddingLeft="#dimen/padding_large"
android:paddingRight="#dimen/padding_large"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<helper.CustomFontMontserratBoldTextView
android:id="#+id/booking_history_name"
android:layout_marginTop="#dimen/margin_large"
android:layout_marginBottom="3dp"
android:textColor="#color/black"
android:textSize="#dimen/text_medium"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<helper.CustomFontMontserratMediumTextView
android:id="#+id/booking_history_code"
android:gravity="end"
android:layout_marginTop="#dimen/margin_large"
android:layout_marginBottom="#dimen/margin_small"
android:textColor="#color/grey_2"
android:textSize="#dimen/text_medium"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
<helper.CustomFontMontserratBoldTextView
android:id="#+id/booking_history_status"
android:background="#color/lightOrange"
android:textColor="#color/black"
android:textSize="#dimen/text_very_small"
android:paddingLeft="#dimen/padding_small"
android:paddingRight="#dimen/padding_small"
android:paddingTop="#dimen/padding_small"
android:paddingBottom="#dimen/padding_small"
android:layout_marginBottom="#dimen/padding_small"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="horizontal"
android:layout_marginBottom="#dimen/padding_medium"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:src="#mipmap/ic_tanggal"
android:layout_width="20dp"
android:layout_height="20dp" />
<helper.CustomFontMontserratRegularTextView
android:visibility="gone"
android:id="#+id/booking_history_day_booked"
android:layout_marginStart="#dimen/margin_small"
android:layout_marginLeft="#dimen/margin_small"
android:textColor="#color/grey"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<helper.CustomFontMontserratMediumTextView
android:id="#+id/booking_history_actual_date"
android:layout_marginStart="#dimen/margin_small"
android:layout_marginLeft="#dimen/margin_small"
android:textColor="#color/grey"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<helper.CustomFontMontserratMediumTextView
android:id="#+id/booking_history_time_booked"
android:layout_marginStart="#dimen/margin_medium"
android:layout_marginLeft="#dimen/margin_medium"
android:textColor="#color/grey"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
XML Activity (Parent of Fragment)
<com.flipboard.bottomsheet.BottomSheetLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/bottomsheet"
android:background="#color/black_image_view">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar_layout"
android:layout_height="?android:attr/actionBarSize"
android:layout_width="match_parent">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar_title_and_description"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/homepage_fragment_menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/appbar_layout"
android:layout_above="#id/navigation"
/>
<include
android:id="#+id/navigation"
layout="#layout/element_bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
<ProgressBar
android:id="#+id/homepage_progressBar"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:visibility="gone" />
</RelativeLayout>
</com.flipboard.bottomsheet.BottomSheetLayout>
AdapterJava
#NonNull
#Override
public BookingHistoryListViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
View view = layoutInflater.inflate(R.layout.adapter_booking_history,parent,false);
context = parent.getContext();
return new BookingHistoryListViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull final BookingHistoryListViewHolder holder, final int position) {
String data = GetDateUtils.convertEpochToDate(dataList.get(position).getActualDate());
if(dataList.get(position).getBookingStatus().equals("Completed") && dataList.get(position).getFlagRating().equals(false)){
Intent intent = new Intent(holder.itemView.getContext(), ProfessionalRatingActivity.class);
intent.putExtra("professionalId", dataList.get(position).getProfessionalId());
intent.putExtra("expertiseId", dataList.get(position).getExpertiseId());
intent.putExtra("professionalName",dataList.get(position).getProfessionalName());
holder.itemView.getContext().startActivity(intent);
}
if(dataList.get(position).getBookingStatus().equals("OnProcess")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.on_process));
}else if(dataList.get(position).getBookingStatus().equals("Cancel")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.cancelled));
}else if(dataList.get(position).getBookingStatus().equals("Completed")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.completed));
}else if(dataList.get(position).getBookingStatus().equals("Reserved")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.reserved));
}else if(dataList.get(position).getBookingStatus().equals("Reschedule")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.rescheduled));
}else if(dataList.get(position).getBookingStatus().equals("Confirmed")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.confirmed));
}
holder.bookingHistoryName.setText(dataList.get(position).getProfessionalName());
holder.bookingHistoryStatus.setText(dataList.get(position).getBookingStatus());
holder.bookingHistoryDayBooked.setText(dataList.get(position).getDayBooked());
holder.bookingHistoryCode.setText(String.format(Locale.getDefault(),"ID: %s",dataList.get(position).getCode()));
holder.bookingHistoryActualDate.setText(String.format(Locale.getDefault(),"%s",data));
holder.bookingHistoryTimeBooked.setText(String.format(Locale.getDefault(),"# %s",dataList.get(position).getTimeBooked()));
holder.bookingHistoryCardview.setOnClickListener(v -> {
Intent intent = new Intent(v.getContext(), BookingHistoryDetailActivity.class);
intent.putExtra("idProfessionalAdapter", dataList.get(position).getId());
holder.itemView.getContext().startActivity(intent);
});
}
#Override
public int getItemCount() {
return dataList!=null ? dataList.size() :0 ;
}

You're nesting your fragment view in a BottomSheetLayout, and according to the source code, the initial visibility is View.INVISIBLE:
private void init() {
// ...
dimView = new View(getContext()); // Line 150
dimView.setBackgroundColor(Color.BLACK);
dimView.setAlpha(0);
dimView.setVisibility(INVISIBLE);
// ...
}
public void setContentView(View contentView) {
super.addView(contentView, -1, generateDefaultLayoutParams());
super.addView(dimView, -1, generateDefaultLayoutParams());
}
I'm not familiar with Flipboard library, but I've got a feeling that you might be using it incorrectly. Maybe try:
bottomSheetLayout.showWithSheetView(...)
Or please check on their GitHub for usage.

Your recycler view in xml layout has `android:visibility="gone". Remove this line or change it to visible.

Related

ListView shows only one item in a ScrollView?

I have a ListView, where i changed appearence of row, but listview have size of one row, instead of fullscreen.
and my scrollview is working but listview is not working.
activity_graph_view.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_graph_table_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="00dp"
android:background="#color/background"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/appbar"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp">
<LinearLayout
android:id="#+id/layoutTableOne"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="5dp"
android:visibility="visible">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Table View"
android:textSize="#dimen/subheading"
android:textColor="#color/subheading"
android:textAllCaps="false" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="#+id/lv_spirometer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#color/mdtp_button_selected"
android:dividerHeight="1dp" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.9"
android:padding="10dp"
android:text="Graph View"
android:textAllCaps="false"
android:textColor="#color/subheading"
android:textSize="#dimen/subheading" />
</LinearLayout>
<com.jjoe64.graphview.GraphView
android:id="#+id/grapfinal"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp"
android:weightSum="1">
<LinearLayout
android:id="#+id/grphtextMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/grphtextColor"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_marginTop="3dp"
android:orientation="vertical" />
<TextView
android:id="#+id/grphtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Hello"
android:textColor="#color/subheading"
android:textSize="14dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/grphtextMain2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/grphtextColor2"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_marginTop="3dp"
android:background="#color/red_btn_bg_color"
android:orientation="vertical" />
<TextView
android:id="#+id/grphtext2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Hello"
android:textColor="#color/subheading"
android:textSize="14dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.9"
android:padding="10dp"
android:text="Graph View"
android:textAllCaps="false"
android:textColor="#color/subheading"
android:textSize="#dimen/subheading" />
</LinearLayout>
<com.jjoe64.graphview.GraphView
android:id="#+id/grapfinal1"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp"
android:weightSum="1">
<LinearLayout
android:id="#+id/grphtextMain1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/grphtextColor1"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_marginTop="3dp"
android:background="#color/red_btn_bg_color"
android:orientation="vertical" />
<TextView
android:id="#+id/grphtext1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Hello"
android:textColor="#color/subheading"
android:textSize="14dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
</RelativeLayout>
spirometer_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
app:cardBackgroundColor="#fff4f4f3"
app:cardElevation="10dp"
app:cardPreventCornerOverlap="true"
card_view:cardCornerRadius="8dp">
<LinearLayout
android:padding="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_marginLeft="10dp"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/tv_fvc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FVC 3.15 L" />
<TextView
android:id="#+id/tv_fev1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FEV1 2.44 L" />
<TextView
android:id="#+id/tv_pef"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PEF 3.74 L/s" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
CustomAdapter1.java
public class CustomAdapter1 extends BaseAdapter {
ArrayList<GetUserSpirometer> arrayList;
public CustomAdapter1(ArrayList<GetUserSpirometer> arrayList){
this.arrayList=arrayList;
Log.e("arraylist length",""+arrayList.size());
}
#Override
public int getCount() {
return arrayList.size();
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater= getLayoutInflater();
ViewHolder1 holder=new ViewHolder1();
convertView = inflater.inflate(R.layout.spirometer_item, parent, false);
holder.tv_date=(TextView)convertView.findViewById(R.id.tv_date);
holder.tv_fvc=(TextView)convertView.findViewById(R.id.tv_fvc);
holder.tv_fev1=(TextView)convertView.findViewById(R.id.tv_fev1);
holder.tv_pef=(TextView)convertView.findViewById(R.id.tv_pef);
String[] arr = getDate(Long.parseLong(arrayList.get(position).get_date()), "MMM dd, yyy/hh:mm a").split("/");
holder.tv_date.setText(arr[0] + "\n" + arr[1]);
holder.tv_fvc.setText(arrayList.get(position).get_userfvc());
holder.tv_fev1.setText(arrayList.get(position).get_userfev1());
holder.tv_pef.setText(arrayList.get(position).get_userpef());
convertView.setTag(holder);
return convertView;
}
}
Items are not scrolling.
how to solve this. please help.
thanks in advance.
Then you need to change itemView's xml file ,
android:layout_height="match_parent"
instead of like ,
android:layout_height="wrap_content"
Simple change in spirometer_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
....Your design code
</LinearLayout>
I was having problem with the same from such a long time. Then I found a solution that worked for me.
Add a ListViewHelper java class. Here below is code for ListViewHelper.java
package com.molescope;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
public class ListViewHelper {
public static void getListViewSize(ListView listView){
ListAdapter adapter = listView.getAdapter();
if(adapter!=null){
int totalHeight = 0;
//setting list adapter in loop tp get final size
for (int i=0; i<adapter.getCount(); i++){
View listItem = adapter.getView(i, null, listView);
listItem.measure(0,0);
totalHeight += listItem.getMeasuredHeight();
}
//setting listview items in adapter
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() *
(adapter.getCount()-1));
listView.setLayoutParams(params);
}else{
return;
}
}
}
And after adding this java file, in your code wherever you are setting adapter to listview, right after that line add the code below:
ListView myList=(ListView) findViewById(R.id.listView);
myList.setAdapter(new ArrayAdapter<String>.
(this,android.R.layout.simple_list_item_1, listview_array));
ListViewHelper.getListViewSize(myList);

Button does not get clicked on the first attempt

There are a few buttons in my activity which do not get clicked on the first attempt but they get clicked from the second time onwards. It seems that the button gets focus on the first click and gets actually pressed from the second time onwards. What can be the reason that these buttons do not get clicked the first time?
I have noticed that this behaviour is only shown by buttons that are at the very bottom of my activity.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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="match_parent"
android:layout_height="match_parent"
tools:context="com.me.proj.view.activities.MallActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="200dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
app:title=" "
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v4.view.ViewPager
android:id="#+id/viewpager_mall_showcase_images"
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"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffe5e5e5"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<include layout="#layout/info_card" />
<include layout="#layout/photo_card" />
<include layout="#layout/address_card" />
<include layout="#layout/opening_hours_card" />
<include layout="#layout/review_card" /> <!-- Button in this file has the problem-->
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
review_card.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="0.5dp"
card_view:cardMaxElevation="1dp"
card_view:cardPreventCornerOverlap="false"
card_view:cardUseCompatPadding="true"
android:layout_width="match_parent"
android:layout_marginTop="7dp"
android:background="#color/colorWhite"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorWhite">
<TextView
android:id="#+id/txt_rating"
android:background="#drawable/blue_button_background"
android:text="3.8"
android:textColor="#color/colorWhite"
android:layout_marginTop="10dp"
android:textSize="24sp"
android:gravity="center"
android:layout_marginStart="10dp"
android:layout_width="60dp"
android:layout_height="40dp" />
<TextView
android:id="#+id/txt_reviews_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/primary_text"
android:textSize="16sp"
android:layout_toEndOf="#+id/txt_rating"
android:layout_marginStart="20dp"
android:textStyle="bold"
android:paddingTop="1dp"
android:layout_alignTop="#+id/txt_rating"
android:text="Based on 98 reviews"/>
<TextView
android:id="#+id/txt_read_all_reviews"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Read All Reviews"
android:layout_alignStart="#id/txt_reviews_title"
android:layout_toEndOf="#id/txt_rating"
android:layout_alignBottom="#id/txt_rating"
android:gravity="bottom"
android:paddingBottom="1dp"
android:textColor="#color/red"
android:layout_below="#id/txt_reviews_title"/>
<View
android:id="#+id/view_dummy1"
android:layout_width="match_parent"
android:layout_height="0.2dp"
android:layout_below="#id/txt_read_all_reviews"
android:layout_marginTop="10dp"
android:background="#color/divider"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginStart="16dp"
android:layout_below="#+id/view_dummy1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="0.6"
android:layout_marginBottom="10dp"
android:orientation="vertical">
<TextView
android:id="#+id/txt_how_did_your_visit_go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="How did your visit go?"
android:textStyle="bold"
android:textSize="14sp"
android:textColor="#color/primary_text" />
<TextView
android:id="#+id/txt_tell_everyone_about_it"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tell everyone about it!"
android:layout_marginTop="5dp"
android:textColor="#color/secondary_text"
android:textSize="12sp"
/>
</LinearLayout>
<!--This got some problem-->
<Button
android:id="#+id/btn_add_review"
android:layout_width="0dp"
android:layout_height="40dp"
android:text="Add Your Review"
android:layout_marginEnd="16dp"
android:layout_marginTop="8dp"
android:textAllCaps="false"
android:textColor="#color/colorWhite"
android:background="#drawable/blue_button_background"
android:layout_weight="0.5"/>
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn_add_review).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "clicked", Toast.LENGTH_SHORT).show();
}
});
}
Code in my MainActivity.class:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View view = findViewById(R.id.sub_layout);
Button button = (Button) view.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Do your stuff
Toast.makeText(MainActivity.this, "hi", Toast.LENGTH_SHORT).show();
}
});
}
}
Code in my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="eflair.myapplication.MainActivity">
<include
android:id="#+id/sub_layout"
layout="#layout/sub_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.constraint.ConstraintLayout>
Code in my sub_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
</LinearLayout>
This issue is actually a bug in the NestedScrollView class for a while now.
I solved this issue my making some tweaks to the source code of the NestedScrollView class, as follows :-
public class NestedScrollView extends FrameLayout implements NestedScrollingParent,
NestedScrollingChild, ScrollingView {
...
#Override
public boolean onTouchEvent(MotionEvent ev) {
switch (actionMasked) {
case MotionEvent.ACTION_DOWN: {
if (getChildCount() == 0) {
return false;
}
//add this condition
if (!inChild((int) ev.getX(), (int) ev.getY())) {
return false;
}
if ((mIsBeingDragged = !mScroller.isFinished())) {
final ViewParent parent = getParent();
if (parent != null) {
parent.requestDisallowInterceptTouchEvent(true);
}
}
...
}
}
#Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
...
switch (action & MotionEventCompat.ACTION_MASK) {
...
case MotionEvent.ACTION_DOWN: {
...
// replace this line:
// mIsBeingDragged = !mScroller.isFinished();
mIsBeingDragged = false;
...
}
}
}
}
After doing this it should work fine.

RecyclerView not showing up properly (scrunched up)

I've been trying to implement multiple RecyclerView within a layout that is part of a collapsing tab. However, my RecyclerView hasn't been working and I don't know what I did wrong in my code. Please help me!
Here is the Github Link: github.com/arxbombus/RecipeDetails
Here is the desired view: image
Here is what I'm getting for some reason: image
As you can see, everything is all scrunched up. :(
Below I've included the layouts for my MainActivity and also the Java files for my Adapters.
Here is my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="400dp"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="400dp"
app:title="Some Randome Recipe"
app:titleEnabled="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="#+id/ivParallax"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/food"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtAbout"
android:text="About this recipe"
android:textStyle="bold"
android:textSize="13sp"
android:padding="15dp"
android:layout_marginBottom="-25dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtRecipeDescription"
android:text="#string/recipe_description"
android:padding="15dp"
android:layout_marginBottom="-5dp"
android:textSize="12sp"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/colorDivider"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtInfo"
android:text="Info"
android:textStyle="bold"
android:textSize="13sp"
android:padding="15dp"
android:layout_marginBottom="-20dp"
android:layout_marginTop="-5dp"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/rvRecipeInfo"
android:layout_width="match_parent"
android:layout_height="75dp"
android:layout_gravity="center_vertical"
android:orientation="horizontal"
android:padding="15dp"></android.support.v7.widget.RecyclerView>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/colorDivider"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtIngredient"
android:text="Ingredients"
android:textStyle="bold"
android:textSize="13sp"
android:padding="15dp"
android:layout_marginBottom="-20dp"
android:layout_marginTop="-5dp"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/rvRecipeIngredient"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="15dp"></android.support.v7.widget.RecyclerView>
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/colorDivider"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
/>
walking
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtProcedures"
android:text="Procedures"
android:textStyle="bold"
android:textSize="13sp"
android:padding="15dp"
android:layout_marginBottom="-20dp"
android:layout_marginTop="-5dp"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/rvRecipeProcedure"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="15dp"></android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
And my CardView
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/recipeInfoCards"
android:layout_width="81dp"
android:layout_height="75dp"
app:cardCornerRadius="6dp"
android:elevation="15dp"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorRecipeInfoCardBG"
android:padding="10dp"
android:orientation="vertical">
<TextView
android:id="#+id/txtRecipeInfoCardTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cooking Time:"
android:textSize="11sp"
android:textColor="#android:color/black"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:layout_marginTop="5dp"
/>
<TextView
android:id="#+id/txtRecipeInfoCardDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="20 Minutes"
android:textSize="11sp"
android:textColor="#color/colorTextSecondary"
android:layout_gravity="center_horizontal"
android:gravity="center"/>
</LinearLayout>
</android.support.v7.widget.CardView>
And here are my MainActivity and Adapters respectiviely
public class MainActivity extends AppCompatActivity {
ArrayList < Recipe > recipeData;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
recipeData = new ArrayList < Recipe > ();
createData();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
RecyclerView recipeInfoCardRV = (RecyclerView) findViewById(R.id.rvRecipeInfo);
recipeInfoCardRV.setHasFixedSize(true);
recipeInfoCardRV.setNestedScrollingEnabled(false);
RecipeInfoAdapter recipeInfoAdapter = new RecipeInfoAdapter(this, recipeData);
recipeInfoCardRV.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
recipeInfoCardRV.setAdapter(recipeInfoAdapter);
RecyclerView recipeIngredientRV = (RecyclerView) findViewById(R.id.rvRecipeIngredient);
recipeIngredientRV.setHasFixedSize(true);
recipeIngredientRV.setNestedScrollingEnabled(false);
recipeIngredientRV.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
RecipeIngredientAdapter recipeIngredientAdapter = new RecipeIngredientAdapter(this, recipeData);
recipeIngredientRV.setAdapter(recipeIngredientAdapter);
}
public void createData() {
ArrayList < RecipeInfoCard > recipeInfoCards = new ArrayList < RecipeInfoCard > ();
recipeInfoCards.add(new RecipeInfoCard("Cooking Time", "20 Minutes"));
recipeInfoCards.add(new RecipeInfoCard("Calories", "3501"));
recipeInfoCards.add(new RecipeInfoCard("Procedures", "Three"));
ArrayList < RecipeIngredient > recipeIngredients = new ArrayList < RecipeIngredient > ();
for (int i = 1; i <= 10; i++) {
recipeIngredients.add(new RecipeIngredient("Ingredient " + i, String.valueOf(i), "grams"));
}
Recipe dm = new Recipe(recipeInfoCards, recipeIngredients);
recipeData.add(dm);
}
}
My adapter for my CardView
public class RecipeInfoAdapter extends RecyclerView.Adapter < RecipeInfoAdapter.RecipeInfoCardItemRowHolder > {
private Context mContext;
private ArrayList < Recipe > recipeData;
public RecipeInfoAdapter(Context mContext, ArrayList < Recipe > recipeData) {
this.mContext = mContext;
this.recipeData = recipeData;
}
#Override
public RecipeInfoCardItemRowHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recipe_info_card_view, null);
return new RecipeInfoCardItemRowHolder(v);
}
#Override
public void onBindViewHolder(RecipeInfoCardItemRowHolder recipeInfoCardItemRowHolder, int position) {
Recipe recipe = recipeData.get(position);
recipeInfoCardItemRowHolder.infoCardTitle.setText(recipe.getRecipeInfoCards().get(position).getRecipeInfoCardTitle());
recipeInfoCardItemRowHolder.infoCardDescription.setText(recipe.getRecipeInfoCards().get(position).getRecipeInfoCardDescription());
}
#Override
public int getItemCount() {
return (null != recipeData ? recipeData.size() : 0);
}
public class RecipeInfoCardItemRowHolder extends RecyclerView.ViewHolder {
protected TextView infoCardTitle;
protected TextView infoCardDescription;
public RecipeInfoCardItemRowHolder(View view) {
super(view);
this.infoCardTitle = (TextView) view.findViewById(R.id.txtRecipeInfoCardTitle);
this.infoCardDescription = (TextView) view.findViewById(R.id.txtRecipeInfoCardDescription);
}
}
}
I didn't put all my code here because I think the question is long enough but I would really appreciate if someone helped me. Thank you!
Try to change your rvRecipeInfo RecyclerView height.. becasue your hardicoading it to 75 dp which is wrong.
<android.support.v7.widget.RecyclerView
android:id="#+id/rvRecipeInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal"
android:padding="15dp"></android.support.v7.widget.RecyclerView>
similer to cardview as well
< ?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/recipeInfoCards"
android:layout_width="100dp"
android:layout_height="75dp"
app:cardCornerRadius="6dp"
android:elevation="15dp"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/colorRecipeInfoCardBG"
android:padding="10dp"
android:orientation="vertical">
<TextView
android:id="#+id/txtRecipeInfoCardTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cooking Time:"
android:textSize="11sp"
android:textColor="#android:color/black"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:layout_marginTop="5dp"
/>
<TextView
android:id="#+id/txtRecipeInfoCardDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="20 Minutes"
android:textSize="11sp"
android:textColor="#color/colorTextSecondary"
android:layout_gravity="center_horizontal"
android:gravity="center"/>
</LinearLayout>
</android.support.v7.widget.CardView>

How to disable nested scrolling of viewpager within the nestedscrollview in android activity?

This is what my nestedscrollview looks like
This is where my viewpager, along with other views and layouts are placed inside that nestedscrollview
Now issue is that the viewpager, which is swiping fragments of recyclerviews left and right, is not scrolling down along with the nestedscrollview. Activity scrolls only upto the tab layout, as shown in the second picture. Viewpager scrolls nested. Can you PLEASE solve this problem?
This is how my main activity's layout looks like:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:id="#+id/main_profile"
android:layout_width="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="430dp"
android:id="#+id/app_bar"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/collapsing_toolbar"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/profile_image"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
android:src="#drawable/sample_image"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="240dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="William Stevenson"
android:textSize="24sp"
android:gravity="center"
android:textColor="#f0f0f0"
android:id="#+id/userName" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Graphic Designer. Freelancer"
android:textSize="16sp"
android:gravity="center"
android:textColor="#f0f0f0"
android:layout_below="#id/userName"
android:id="#+id/tagline"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_below="#id/tagline"
android:layout_marginTop="48dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp">
<Button
android:layout_width="wrap_content"
android:layout_height="48dp"
android:paddingLeft="48dp"
android:paddingRight="48dp"
android:textSize="12sp"
android:textColor="#f0f0f0"
android:text="Follow"
android:layout_centerHorizontal="true"
android:id="#+id/follow"
android:background="#drawable/follow_button_flat"/>
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_toLeftOf="#id/follow"
android:layout_centerVertical="true"
android:id="#+id/voiceCallMessage"
android:src="#drawable/ic_mic_none_white_48dp"
android:layout_marginRight="32dp" />
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_toRightOf="#id/follow"
android:layout_centerVertical="true"
android:id="#+id/videoCallMessage"
android:layout_marginLeft="32dp"
android:src="#drawable/ic_videocam_white_48dp" />
</RelativeLayout>
</RelativeLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:rippleColor="#303030"
app:backgroundTint="#3292D3"
app:layout_anchor="#id/app_bar"
android:src="#drawable/ic_bubble_chart_white_48dp"
app:fabSize="normal"
app:layout_anchorGravity="bottom|right"/>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:id="#+id/nestedScrollView">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_marginLeft="48dp"
android:layout_marginRight="48dp"
android:id="#+id/profileStats"
android:orientation="horizontal">
...
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="256dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="48dp"
android:id="#+id/imagesAndVideos"
android:layout_below="#id/profileStats">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/frame_layout_corner"
android:clickable="false">
...
</TableLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="800+ Images"
android:layout_gravity="center"
android:gravity="center"
android:textColor="#f0f0f0"
android:id="#+id/imagesTag"
android:textSize="18sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="32dp"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:text="Show All"
android:gravity="center"
android:id="#+id/showAll"
android:background="#drawable/follow_button_flat"
android:textColor="#f0f0f0"
android:textSize="14sp"/>
</LinearLayout>
</FrameLayout>
<com.gigamole.navigationtabstrip.NavigationTabStrip
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginLeft="48dp"
android:layout_marginRight="48dp"
app:nts_animation_duration="300"
app:nts_factor="1.2"
app:nts_size="16dp"
app:nts_type="line"
app:nts_titles="#array/posts_and_friends"
android:layout_below="#id/imagesAndVideos"
android:layout_marginTop="48dp"
android:id="#+id/post_and_friends_nav_strip"/>
<!--Problem is here-->
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/posts_friends_view_pager"
android:layout_below="#id/post_and_friends_nav_strip"
android:layout_marginTop="16dp"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
This is what my both the fragments looks like:
Fragment 1's layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainPosts"
android:layout_height="wrap_content"/>
Fragment 2's layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/friends"
android:layout_height="wrap_content"/>
Yeah, almost similar.
Edit: I've tried setting android:nestedScrollingEnabled to false in the recyclerview. But It just stops scrolling of the viewpager. Activity can't be scrolled down below the tab layout of the viewpager. Viewpager remains below the phone screen.
Edit 2: This is what my main activity looks like:
public class Profile extends AppCompatActivity {
TextView userName, tagline, followers, followersTag, points, pointsTag, following, followingTag, imagesTag;
ImageView userImage, sample1, sample2, sample3, sample4;
Button showAllImages;
Typeface robotoRegular, robotoLight;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_profile);
initActivity();
ViewPager postsAndFriendsViewPager = (ViewPager) findViewById(R.id.posts_friends_view_pager);
FragmentManager fragmentManager = getSupportFragmentManager();
ViewPagerAdapterPostsFriends viewPagerAdapterPostsFriends = new ViewPagerAdapterPostsFriends(fragmentManager);
postsAndFriendsViewPager.setAdapter(viewPagerAdapterPostsFriends);
NavigationTabStrip navigationTabStrip = (NavigationTabStrip) findViewById(R.id.post_and_friends_nav_strip);
navigationTabStrip.setTabIndex(0);
navigationTabStrip.setStripColor(Color.TRANSPARENT);
navigationTabStrip.setActiveColor(Color.RED);
navigationTabStrip.setInactiveColor(Color.DKGRAY);
navigationTabStrip.setViewPager(postsAndFriendsViewPager);
}
class ViewPagerAdapterPostsFriends extends FragmentStatePagerAdapter
{
ViewPagerAdapterPostsFriends(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
if(position == 0)
return Posts.init();
return ProfileFriends.init();
}
#Override
public int getCount() {
return 2;
}
}
private void initActivity()
{
userImage = (ImageView) findViewById(R.id.profile_image);
sample1 = (ImageView) findViewById(R.id.sample1);
sample2 = (ImageView) findViewById(R.id.sample2);
sample3 = (ImageView) findViewById(R.id.sample3);
sample4 = (ImageView) findViewById(R.id.sample4);
userName = (TextView) findViewById(R.id.userName);
imagesTag = (TextView) findViewById(R.id.imagesTag);
tagline = (TextView) findViewById(R.id.tagline);
points = (TextView) findViewById(R.id.points);
pointsTag = (TextView) findViewById(R.id.pointsTag);
followers = (TextView) findViewById(R.id.followers);
followersTag = (TextView) findViewById(R.id.followersTag);
following = (TextView) findViewById(R.id.following);
followingTag = (TextView) findViewById(R.id.followingTag);
showAllImages = (Button) findViewById(R.id.showAll);
robotoLight = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Light.ttf");
robotoRegular = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Regular.ttf");
Picasso.with(this).load(R.drawable.sample_image).transform(new BrightnessFilterTransformation(this, -0.1f)).into(userImage);
userName.setTypeface(robotoLight);
imagesTag.setTypeface(robotoLight);
tagline.setTypeface(robotoLight);
points.setTypeface(robotoRegular);
pointsTag.setTypeface(robotoRegular);
followers.setTypeface(robotoRegular);
followersTag.setTypeface(robotoRegular);
following.setTypeface(robotoRegular);
followingTag.setTypeface(robotoRegular);
showAllImages.setTypeface(robotoLight);
}
}

how to create recycler view using card view with grid layout in android

I want to create layout for my app. I already tried to create but I am not able to get the desired UI. Actually i am fresher in android development and I need help for improving my knowledge in android development.
Please find attached snapshot below:
Thanks in advance.
i want to create this type of layout.
i already created like this here it is my code. raw_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/cvList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
app:cardElevation="8dp"
app:cardUseCompatPadding="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent">
<!-- Your content here -->
<ImageView
android:id="#+id/ListImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="230dp"
android:scaleType="center"
android:src="#mipmap/ic_launcher" />
<RelativeLayout
android:id="#+id/footerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:paddingBottom="#dimen/value_5dp"
android:paddingLeft="#dimen/value_15dp"
android:paddingRight="#dimen/value_15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/overflow"
android:orientation="vertical">
<TextView
android:id="#+id/ListTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="ListTitle"
android:textSize="#dimen/value_15sp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
</HorizontalScrollView>
</ScrollView>
</android.support.v7.widget.CardView>
my output is like that [my output][2]
Please Check Below XML file for your Recycler View raw file
raw_grid
<android.support.v7.widget.CardView 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/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/scale_10dp"
android:layout_marginLeft="#dimen/scale_5dp"
android:layout_marginRight="#dimen/scale_5dp"
app:cardElevation="2dp"
card_view:cardCornerRadius="8dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<android.support.v7.widget.AppCompatImageView
android:id="#+id/ivImages"
android:layout_width="match_parent"
android:layout_height="#dimen/scale_150dp"
android:scaleType="centerCrop"
android:src="#drawable/dummy_1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="#dimen/scale_10dp">
<android.support.v7.widget.AppCompatTextView
android:id="#+id/tvTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="HMS Scrap"
android:textColor="#color/aluminum" />
<android.support.v7.widget.AppCompatTextView
android:id="#+id/tvCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="(20)"
android:textColor="#color/aluminum" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
activity_main
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:orientation="vertical">
<include layout="#layout/toolbar" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:clipToPadding="false"
android:paddingTop="#dimen/scale_10dp" />
</LinearLayout>
MainActivity
public class SubCategoryActivity extends AppCompactActivity {
private RecyclerView recyclerView;
private GridLayoutManager layoutManager;
private LinearLayout llProgress, llError;
private AppCompatTextView tvEmpty;
private SubCategoryAdapter mAdapter;
private String title = "";
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_business_info);
init();
}
private void init() {
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
llProgress = (LinearLayout) findViewById(R.id.llProgress);
llError = (LinearLayout) findViewById(R.id.llErrorMessage);
tvEmpty = (AppCompatTextView) findViewById(R.id.tvEmpty);
layoutManager = new GridLayoutManager(MainActivity.this, 2);
recyclerView.setLayoutManager(layoutManager);
mAdapter = new SubCategoryAdapter(MainActivity.this, clickListener);
recyclerView.setAdapter(mAdapter);
}
}

Categories

Resources