RecyclerView won't Scroll - android

I made a fragment which contains 3 RecyclerView, 1 which is a horizontal RV works, but the other 2 which is vertical doesn't work. I couldn't scroll through it.
(image link: [http://s15.postimg.org/lc6bxz9ej/so1.png][2])
HomeFragment.java #AfterViews
LinearLayoutManager catLM = new LinearLayoutManager(mContext);
mRVcatList.setLayoutManager(catLM);
mRVcatList.setAdapter(new CategoryAdapter(initCategories()));
LinearLayoutManager hotLM = new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false);
mRVhotList.setLayoutManager(hotLM);
mRVhotList.setAdapter(new HotItemsAdapter(initHotItems()));
LinearLayoutManager brandLM = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false);
mRVbrandList.setLayoutManager(brandLM);
mRVbrandList.setAdapter(new BrandAdapter(initBrands()));
mRVbrandList.addOnItemTouchListener(new HotItemClickListener(mContext, new HotItemClickListener.OnItemClickListener() {
#Override
public void onItemClick(View view, int position) {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.mFLframe, new ProductListFragment_());
transaction.addToBackStack(null);
transaction.commit();
}
}));
mRVcatList.addOnItemTouchListener(new HotItemClickListener(mContext, new HotItemClickListener.OnItemClickListener() {
#Override
public void onItemClick(View view, int position) {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.mFLframe, new CategoryFragment_());
transaction.addToBackStack(null);
((MainActivity) mContext).hideLogo();
transaction.commit();
}
}));
mRVhotList.addOnItemTouchListener(new HotItemClickListener(mContext, new HotItemClickListener.OnItemClickListener() {
#Override
public void onItemClick(View view, int position) {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.mFLframe, new DetailFragment_());
transaction.addToBackStack(null);
((MainActivity) mContext).hideLogo();
transaction.commit();
}
}));
And here is my XML file,
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<!--//HOT-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/mRLtopHot">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hot Items"
android:textColor="#color/ColorPrimaryDark"
android:paddingLeft="5dp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/mTVhot"
android:textSize="#dimen/bebas_medium" />
<View
android:layout_width="wrap_content"
android:layout_height="2dip"
android:background="#00B7F6"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/mRVhotList"
android:layout_width="match_parent"
android:layout_height="140dp"
android:padding="5dp"
android:background="#FFFFFF"
android:layout_below="#+id/mRLtopHot"/>
<!--CAT-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#FFFFFF"
android:layout_marginTop="10dp"
android:id="#+id/mRLtopCat"
android:layout_below="#+id/mRVhotList"
android:layout_centerHorizontal="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Categories"
android:paddingLeft="5dp"
android:textColor="#color/ColorPrimaryDark"
android:id="#+id/mTVcat"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:clickable="false"
android:textSize="#dimen/bebas_medium" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/mIVcatCollapse"
android:paddingRight="5dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<View
android:id="#+id/view1"
android:layout_width="wrap_content"
android:layout_height="2dip"
android:background="#00B7F6"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/mRVcatList"
android:layout_width="match_parent"
android:layout_height="140dp"
android:background="#FFFFFF"
android:layout_below="#+id/mRLtopCat"/>
<!--BRAND-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:id="#+id/mRLtopBrand"
android:background="#FFFFFF"
android:layout_below="#+id/mRVcatList"
android:layout_centerHorizontal="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Brands"
android:paddingLeft="5dp"
android:textSize="#dimen/bebas_medium"
android:textColor="#color/ColorPrimaryDark"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/mTVbrand" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:id="#+id/mIVbrandCollapse"
android:background="#drawable/abc_ic_menu_moreoverflow_mtrl_alpha"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<View
android:layout_width="wrap_content"
android:layout_height="2dip"
android:background="#00B7F6"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/mRVbrandList"
android:layout_width="match_parent"
android:layout_height="140dp"
android:background="#FFFFFF"
android:layout_below="#+id/mRLtopBrand"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
Previously, I made the "Categories" and "Brand" tab closed and could be expanded when clicked (it's just a simple usage of setVisibility), and the RecyclerView(s) did scroll! But I don't use that UI anymore. Unfortunately, this problem arises.
How could I make the vertical RecyclerView works? Thanks!

You can't have a list style layout inside a ScrollView (The ScrollView will destroy the listview/gridview/recyclerview scroll function)
You must get the height of the RecyclerView to make it fixed. Here is an example: Android list view inside a scroll view
Or, you can use this library but it use a ListView: https://github.com/PaoloRotolo/ExpandableHeightListView (maybe will work with RecyclerView)

Related

Recyclerview doesn't show or scroll in fragment

I have found some questions regarding this issue here but none of them helped to solve my problem. Recycler view works fine but there is issue in lollipop version. It works perfectly in an activity but doesn't show or scroll when used inside fragment. My fragment screen appears blank but the tap listeners in recycler view's adapter is working. When I migrated my fragment code to an activity, it worked fine. I am using 28.0.0 Here is my xml code.
<?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">
<include layout="#layout/toolbar" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipeToRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/initial_layout_empty_view" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView_order"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:nestedScrollingEnabled="false" />
</FrameLayout>
</android.support.v4.widget.SwipeRefreshLayout>
My item xml
<android.support.v7.widget.CardView 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"
android:layout_marginBottom="10dp"
android:orientation="vertical">
<LinearLayout
android:id="#+id/wholeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/txtVendorName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/colorTextListTitle"
android:textSize="16sp"
android:textStyle="bold"
tools:text="Redsun Family Restaurant" />
<TextView
android:id="#+id/txtVendorAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/colorTextNormal"
android:textSize="14sp"
android:textStyle="bold"
tools:text="KumariPati,Lalitpur,Nepal" />
</LinearLayout>
<ImageView
android:id="#+id/imageCompleted"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_check_green"
android:visibility="gone" />
<Button
android:id="#+id/btnDeliveryStatus"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:background="#drawable/circular_btn_background_dark_green"
android:backgroundTint="#color/colorPrimary"
android:text="Accept"
android:textColor="#color/white"
android:textSize="12sp"
android:visibility="gone" />
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp">
<include layout="#layout/layout_seperator" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:orientation="horizontal">
<include
android:id="#+id/included"
layout="#layout/layout_vendor_logo" />
<View
android:id="#+id/catLogoDivider"
android:layout_width="0.7dp"
android:layout_height="match_parent"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="#e8e8e8" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/relOrderNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/txtLblOrderNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:singleLine="true"
android:text="#string/txtOrderNo"
android:textColor="#color/colorTextNormal" />
<TextView
android:id="#+id/txtOrderNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/txtLblOrderNo"
android:gravity="end"
android:maxLines="2"
android:textColor="#color/black"
tools:text="#16-0131-102716" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relDeliveryTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/txtLblDeliveryTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:singleLine="true"
android:text="#string/txtDeliveryTime"
android:textColor="#color/colorTextNormal" />
<TextView
android:id="#+id/txtDeliveryTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/txtLblDeliveryTime"
android:gravity="end"
android:maxLines="2"
android:textColor="#color/black"
tools:text="Jul 5, 2017, 7:15pm" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="32dp"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/txtLblStatus"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:gravity="center"
android:text="#string/txtStatus"
android:textColor="#color/colorTextNormal" />
<TextView
android:id="#+id/txtStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:gravity="end"
android:maxLines="2"
android:textSize="14sp"
android:textColor="#color/black"
tools:text="Processing" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/txtTotalAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerInParent="true"
android:text="#string/txtTotalAmount"
android:textColor="#color/colorTextNormal" />
<TextView
android:id="#+id/txtTotalAmountValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:textColor="#color/black"
tools:text="Rs. 197.50" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
And the long fragment code
public class OrderFragment extends MvpFragment<OrderView, OrderListPresenter> implements OrderView, OnItemClickListener {
private View view;
private Toolbar mToolbar;
private RecyclerView recyclerView;
private SwipeRefreshLayout swipeRefreshLayout;
private List<Order> orderList = new ArrayList<>();
private OrderAdaptor adaptor;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_order, container, false);
return view;
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
findViews();
setActionBar();
initRecyclerView();
initSwipeToRefresh();
if (getActivity() != null)
getActivity().setTitle(getString(R.string.titleOrders));
presenter.getOrderData();
}
#Override
public OrderListPresenter createPresenter() {
return new OrderListPresenter(getContext());
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home)
if (getActivity() != null) {
((MainActivity) getActivity()).openDrawerLayout();
}
return super.onOptionsItemSelected(item);
}
#Override
public void setAdaptor(List<Order> orderList) {
hideLoading();
this.orderList.clear();
this.orderList.addAll(orderList);
adaptor.notifyDataSetChanged();
}
#Override
public void showLoading() {
swipeRefreshLayout.setRefreshing(false);
if (getActivity() != null)
ProgressDialogFactory.getInstance(getActivity()).show();
}
#Override
public void initSwipeToRefresh() {
swipeRefreshLayout.setOnRefreshListener(() -> {
showLoading();
presenter.getOrderData();
});
}
#Override
public void onItemClicked(int position) {
// Don't navigate if order is completed
if (!orderList.get(position).getStatusId().equals(Constants.ORDER_STATUS_DELIVERED))
GlobalUtils.navigateActivityWithMultipleData(getContext(), false, OrderDetailActivity.class, R.anim.slide_in_left, R.anim.no_change, orderList.get(position).getOrderId(), orderList.get(position).getStatusDisplay());
}
private void findViews() {
mToolbar = view.findViewById(R.id.mToolbar);
recyclerView = view.findViewById(R.id.recyclerView_order);
swipeRefreshLayout = view.findViewById(R.id.swipeToRefresh);
}
private void initRecyclerView() {
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
recyclerView.setHasFixedSize(true);
recyclerView.setVisibility(View.VISIBLE);
adaptor = new OrderAdaptor(orderList, this);
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setAdapter(adaptor);
recyclerView.setNestedScrollingEnabled(false);
}
private void setActionBar() {
if (getActivity() == null)
return;
setHasOptionsMenu(true);
((AppCompatActivity) getActivity()).setSupportActionBar(mToolbar);
ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
if (actionBar != null) {
actionBar.setHomeAsUpIndicator(R.drawable.ic_menu);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
}
}
}
God Damn! After being stuck in this issue for 2 whole days, I finally found the solution. It was because I was using FragmentTransaction.TRANSIT_FRAGMENT_FADE when adding fragment inside activity. Removing the transition solved my problem

How start New Activity when Click on Title Of HEADER_VIEW in RecyclerView To display items in IT

enter image description here
In Activty one i have RecyclerView with to View :
HEADER_VIEW
ITEM_VIEW
Header_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#FFF7F7F7">
<TextView
android:id="#+id/tv_group_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:text="TextView"
android:textColor="#F50057"
android:textSize="20sp" />
<TextView
android:id="#+id/more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_weight="1"
android:text="More..." />
</RelativeLayout>
Item_view.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"
android:id="#+id/ll_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/cv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:elevation="3dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:src="#mipmap/ic_launcher" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_below="#id/imageView"
android:background="#f5fff2">
<TextView
android:id="#+id/tv_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:text="name"
android:textAlignment="center"
android:textColor="#FF20C200"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/new_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/old_price"
android:layout_marginRight="5dp"
android:layout_marginStart="5dp"
android:layout_toEndOf="#+id/old_price"
android:text="480.00 DA"
android:textColor="#FF65C2FD"
android:textStyle="bold" />
<TextView
android:id="#+id/old_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/tv_name"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:layout_marginStart="5dp"
android:text="250.00 DA"
android:textAlignment="center"
android:textColor="#F50057" />
<ImageButton
android:id="#+id/overflow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignTop="#+id/new_price"
android:layout_marginEnd="5dp"
android:layout_marginLeft="5dp"
android:background="?attr/selectableItemBackgroundBorderless"
app:srcCompat="#drawable/ic_more_vert_black_24dp" />
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
I created the Adapter and it Work Fine .
My problem is :
I need when I click on more TextView In HEADER_VIEW an New Activity Start
with Specific Itemes Of Stection.
My try :
In Adapter Exactly in onBindViewHolder
#Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
//Context context = mContextWeakReference.get();
if (mContext == null) {
return;
}
if (SECTION_VIEW == getItemViewType(position)) {
final SectionViewHolder sectionViewHolder =(SectionViewHolder)holder;
GroupTitleModel sectionItem = ((GroupTitleModel) mUsersAndSectionList.get(position));
sectionViewHolder.title.setText(sectionItem.title);
sectionViewHolder.more.setText(sectionItem.moreSection);
sectionViewHolder.more.setOnClickListener( new View.OnClickListener() {
#Override
public void onClick(View view) {
// I TRY TO DO IT HERE BUT NO THINGS
}
} );
return;
}
My first thought is that you are bringing yourself into trouble by doing it this way.
You separate the Header view and its Content view, so the problem appear when the Header has no idea which content to continue to next step. If you don't want to refactor than it's ok, there will be a workaround. But my suggestion is that you combine the header and the content into 1 ViewHolder, keep the title, more text, and items inside 1 Model class too. They need to go with each other so they know how to handle with interaction

Android - I want Navigation button and viewpager do the same function

I am working in project that contain framelayout display fragments by navigation button next , back and I provide it method below in my code till now every thing works great
here is why I am here , I need make the same function done with navigation button done with swipe button , I add viewpager and pass all fragment to adapter but it give me different view overlapping
Fragment mFragmentsList[] = new Fragment[]{new Slide2Frag() , .... new Slide23Frag()};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// here is what I need to add viewpager
ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);
adapter = new ViewPageAdapter(getSupportFragmentManager(), mFragmentsList);
mViewPager.setAdapter(adapter);
DisplayFragment(count);
}
// display fragment method
private void DisplayFragment(int display) {
Fragment fragment = null;
switch (display) {
case 2:
fragment = new Slide2Frag();
break;
}
FragmentManager mFragmentManager = getSupportFragmentManager();
FragmentTransaction mTransaction = mFragmentManager.beginTransaction();
mTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
mTransaction.replace(R.id.container, fragment).commit();
}
private void NextMethod() {
if (count < 23) {
count++;
} else {
count = 2;
}
DisplayFragment(count);
}
private void backMethod() {
if (count > 2) {
count--;
} else {
count = 23;
}
DisplayFragment(count);
}
my xml code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:fitsSystemWindows="true"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/headerlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="5dp">
<ImageView
android:id="#+id/home_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="right"
android:layout_marginEnd="219dp"
android:layout_marginRight="219dp"
android:adjustViewBounds="true"
android:background="#drawable/home" />
<ImageView
android:id="#+id/close_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="60dp"
android:layout_marginRight="60dp"
android:adjustViewBounds="true"
android:background="#drawable/close" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="300dp"
android:layout_height="120dp"
android:layout_marginLeft="25dp"
android:adjustViewBounds="true"
android:background="#drawable/aciloc" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="370dp"
android:layout_height="50dp"
android:layout_below="#+id/home_btn"
android:layout_marginBottom="10dp"
android:layout_toEndOf="#+id/imageView3"
android:layout_toRightOf="#+id/imageView3"
android:adjustViewBounds="true"
android:background="#drawable/leadingppi"
android:scaleType="centerInside" />
</RelativeLayout>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_above="#+id/footer_layout"
android:layout_below="#+id/headerlayout" >
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
<LinearLayout
android:id="#+id/footer_layout"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal"
android:weightSum="6">
<ImageButton
android:id="#+id/left_nav"
android:layout_width="30dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:layout_weight="0.5"
android:adjustViewBounds="true"
android:background="#drawable/left_back"
android:scaleType="centerInside" />
<Button
android:id="#+id/ac20"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/btn_background"
android:textColor="#color/text_color"
android:text="Aciloc 20mg" />
<Button
android:id="#+id/ac40"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/btn_background"
android:textColor="#color/text_color"
android:text="Aciloc 40mg" />
<Button
android:id="#+id/profile"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/btn_background"
android:textColor="#color/text_color"
android:text="PROFILE" />
<Button
android:id="#+id/indications"
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/btn_background"
android:textColor="#color/text_color"
android:text="INDICATIONS & DOSAGE" />
<Button
android:id="#+id/pack"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/btn_background"
android:textColor="#color/text_color"
android:text="UNIQUE PACK" />
<ImageButton
android:id="#+id/right_nav"
android:layout_width="30dp"
android:layout_height="match_parent"
android:layout_marginLeft="50dp"
android:layout_weight="0.5"
android:adjustViewBounds="true"
android:background="#drawable/right_back"
android:scaleType="centerInside"
android:textColor="#color/text_color"/>
</LinearLayout>
</RelativeLayout>
here is image explain

Android RecyclerView list item doesn't show click animation

As recommended I replaced my ListView by RecyclerView. But now I can't get working the item click animation. Long press animation is working but if I only tap the item I get no tap animation.
I tried different solutions found around here but nothing helped. What is wrong with my code?
The layout that contains the RecyclerView:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/frame_main" tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/recycler_view" />
</RelativeLayout>
This is the list item layout: (I also tried FrameLayout)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="72dp"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/cover"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00:00"
android:id="#+id/time"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="false"
android:layout_marginRight="16dp"
android:layout_marginTop="20dp"
style="#style/Widget.AppCompat.ListView"
android:singleLine="true" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="72dp"
android:layout_marginRight="56dp"
android:id="#+id/linearLayout"
android:gravity="center_vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title"
android:id="#+id/title"
android:textSize="16dp"
style="#style/Widget.AppCompat.ListView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:singleLine="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Artist"
android:id="#+id/artist"
android:textSize="14dp"
style="#style/Widget.AppCompat.ListView"
android:layout_below="#+id/title"
android:layout_alignLeft="#+id/title"
android:layout_alignStart="#+id/title"
android:singleLine="true" />
</LinearLayout>
</RelativeLayout>
Code in my activity's onCreate():
recyclerview = (RecyclerView) findViewById(R.id.recycler_view);
mLayoutManager = new LinearLayoutManager(this);
recyclerview.setLayoutManager(mLayoutManager);
recyclerview.setHasFixedSize(true);
recyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() {
#Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
// enable swipelayout if scrolled to top
try {
int firstPos = mLayoutManager.findFirstCompletelyVisibleItemPosition();
if (firstPos > 0) {
swipeLayout.setEnabled(false);
} else {
swipeLayout.setEnabled(true);
if (recyclerview.getScrollState() == 1 && swipeLayout.isRefreshing()) {
recyclerview.stopScroll();
}
}
} catch (Exception e) {
}
}
});
recyclerview.addOnItemTouchListener(
new RecyclerItemClickListener(MainActivity.this, new RecyclerItemClickListener.OnItemClickListener() {
#Override
public void onItemClick(View view, int position) {
// do something works
}
})
);
I have read through your question, To achieve tap animation you only need to replace the code below found in your list items.
from
android:background="?android:attr/selectableItemBackground"
to
android:foreground="?android:attr/selectableItemBackground"
Hope it helps solve your problem

Shared elements in fragments dont work, textview -> edittext

I have 2 fragments, and want to do a shared element transition between them.
The item in an recyclerview, with an adapter, contains a textview that should be animated to an edittext in the next fragment.
The recyclerview is in an fragment too.
Here's my code:
item layout for viewholder from adapter:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/row_container"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:background="#FAFAFA"
android:elevation="0dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
android:elevation="0dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:elevation="0dp"
>
<RelativeLayout
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#null"
android:elevation="0dp"
android:layout_centerVertical="true"
>
<ImageButton
android:id="#+id/notify_btn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_bookmark_black_24dp"
android:background="#null"
android:tint="#9E9E9E"
android:layout_centerInParent="true"
/>
</RelativeLayout>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="20dp"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_alignParentTop="true"
android:maxLines="1"
android:ellipsize="end"
android:transitionName="title"
/>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/text"
android:layout_below="#id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="20dp"
android:textSize="15sp"
android:maxLines="2"
android:layout_alignParentBottom="true"
android:textColor="#android:color/black"
android:ellipsize="end"
android:transitionName="text"
/>
</RelativeLayout>
<ImageView
android:id="#+id/fav"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="5dp"
android:visibility="invisible"
android:src="#drawable/ic_star_black_24dp"
/>
</RelativeLayout>
MyAdapter class, the item row click:
row.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Fragment frag = new Fragment_Notice();
int tin_title = Integer.parseInt(String.valueOf(title.getText().length()));
if ( (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) &&
( SharedPrefHelper.getBool("shared_transition") == true) &&
( tin_title >= 1 ) ) {
//Exit transition for old fragment
frag.setSharedElementReturnTransition(TransitionInflater.from(context).inflateTransition(R.transition.title_transform));
frag.setExitTransition(TransitionInflater.from(context).inflateTransition(android.R.transition.explode));
//Enter transition for new fragment
frag.setSharedElementEnterTransition(TransitionInflater.from(context).inflateTransition(R.transition.title_transform));
frag.setEnterTransition(TransitionInflater.from(context).inflateTransition(android.R.transition.explode));
ft.replace(R.id.container, frag, "NoticeTag")
.addToBackStack(null)
.addSharedElement(title, "title")
.commit();
} else {
int open = R.anim.abc_fade_in;
int close = R.anim.abc_fade_out;
ft.setCustomAnimations(open, close, open, close)
.replace(R.id.container, frag, "NoticeTag")
.addToBackStack(null)
.commit();
}
}
});
Layout from final fragment:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginRight="10dp"
android:padding="10dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<EditText
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:nextFocusForward="#id/text"
android:imeOptions="actionNext"
android:singleLine="true"
android:ems="16"
android:hint="#string/title"
android:textColor="#212121"
android:textColorHint="#757575"
android:background="#null"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:scrollbars="horizontal"
android:transitionName="title"
/>
<EditText
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/text"
android:textColor="#212121"
android:textColorHint="#757575"
android:background="#null"
android:layout_marginLeft="2dp"
android:transitionName="text"
/>
<View
android:id="#+id/line"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:elevation="0dp"
android:background="#color/grey"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
>
<ImageButton
android:id="#+id/fav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_star_black_24dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:padding="5dp"
android:background="?android:attr/selectableItemBackground"
android:tint="#9E9E9E"
/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="top"
android:id="#+id/snackbar">
</android.support.design.widget.CoordinatorLayout>
The textview doesnt animate to an edittext.
The explode animation appears.
Between activities the animation works.
Any suggestions how to fix?

Categories

Resources