Android RecyclerView Cards not showing` - android

I am new to Android. I have moved heaven and earth to get my app to show RecyclerView with Cards but am not able to,no matter what. Tried a lot of searching on Google and StackOverflow and also on a lot of recommended sites.
My code is as follows:
HomeActivity.java
public class HomeActivity extends AppCompatActivity {
...
private RecyclerView mRecyclerView;
protected void onCreate(Bundle savedInstanceState) {
...
mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
TransactionRecyclerViewAdapter adapter=new TransactionRecyclerViewAdapter(this, getDataSet());
mRecyclerView.setAdapter(adapter);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
...
}
private ArrayList<FavoriteTransaction> getDataSet() {
ArrayList results = new ArrayList<FavoriteTransaction>();
FavoriteTransaction favoriteTransaction1 = new FavoriteTransaction();
favoriteTransaction1.setAmount("11");
favoriteTransaction1.setBody("11 ka recharge");
results.add(favoriteTransaction1);
FavoriteTransaction favoriteTransaction2 = new FavoriteTransaction();
favoriteTransaction2.setAmount("12");
favoriteTransaction2.setBody("12 ka recharge");
results.add(favoriteTransaction2);
FavoriteTransaction favoriteTransaction3 = new FavoriteTransaction();
favoriteTransaction3.setAmount("13");
favoriteTransaction3.setBody("13 ka recharge");
results.add(favoriteTransaction3);
FavoriteTransaction favoriteTransaction4 = new FavoriteTransaction();
favoriteTransaction4.setAmount("14");
favoriteTransaction4.setBody("14 ka recharge");
results.add(favoriteTransaction4);
FavoriteTransaction favoriteTransaction5 = new FavoriteTransaction();
favoriteTransaction5.setAmount("15");
favoriteTransaction5.setBody("15 ka recharge");
results.add(favoriteTransaction5);
return results;
}
}
activity_home.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorgray">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<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>
<include layout="#layout/content_home" />
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nvView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#android:color/white"
app:menu="#menu/activity_home_drawer"
app:headerLayout="#layout/nav_header"/>
</android.support.v4.widget.DrawerLayout>
content_home.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="#+id/container_body"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView"
android:paddingBottom="55dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp">
<include
android:id="#+id/card_list_fav_transact"
layout="#layout/card_list_fav_transact"/>
</LinearLayout>
</ScrollView>
</FrameLayout>
card_list_fav_transact.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/info_text_sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/hdr_lbl_fav"
android:layout_marginBottom="5dp"/>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:scrollbars="vertical"
/>
</LinearLayout>
card_transaction_row.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"
android:id="#+id/card_view"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorwhite">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorwhite">
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:gravity="center"
android:text="190"
android:textColor="#color/colorPrimary"
android:id="#+id/tv_fav_amt"
android:background="#drawable/stl_tv_blue_circle"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:gravity="center_vertical"
android:layout_toRightOf="#+id/tv_fav_amt"
android:layout_toEndOf="#+id/tv_fav_amt">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Body"
android:id="#+id/fav_body"
android:clickable="true"
android:background="#drawable/stl_btn_underline"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="SubText"
android:id="#+id/fav_subtext"
android:clickable="true"
android:background="#drawable/stl_btn_underline"/>
</LinearLayout>
<Button
style="#style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Buy"
android:id="#+id/btn_tr_buy"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="10dp"
android:background="#drawable/stl_btn_blue"
android:textColor="#android:color/white"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
TransactionRecyclerViewAdapter.java
public class TransactionRecyclerViewAdapter extends RecyclerView.Adapter<TransactionViewHolder> {
private ArrayList<FavoriteTransaction> transactionList;
private Context context;
private LayoutInflater inflater;
public TransactionRecyclerViewAdapter(Context context, ArrayList<FavoriteTransaction> myDataset) {
this.transactionList = new ArrayList<>(myDataset);
this.context = context;
this.inflater = LayoutInflater.from(context);
}
#Override
public int getItemCount() {
return this.transactionList.size();
}
#Override
public void onBindViewHolder(TransactionViewHolder contactViewHolder, int i) {
FavoriteTransaction favTransaction = transactionList.get(i);
contactViewHolder.tvAmount.setText(favTransaction.getAmount());
}
#Override
public TransactionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v=inflater.inflate(R.layout.card_transaction_row, parent, false);
TransactionViewHolder viewHolder=new TransactionViewHolder(v);
return viewHolder;
}
}
TransactionViewHolder.java
public class TransactionViewHolder extends RecyclerView.ViewHolder {
TextView tvAmount, tvBody, tvSubText;
public TransactionViewHolder(View itemView) {
super(itemView);
tvAmount = (TextView) itemView.findViewById(R.id.tv_fav_amt);
tvBody = (TextView) itemView.findViewById(R.id.fav_body);
tvSubText = (TextView) itemView.findViewById(R.id.fav_subtext);
}
}
FavoriteTransaction.java
public class FavoriteTransaction {
private int transactionId;
private String amount;
private String subText, body;
public int getTransactionId() {
return transactionId;
}
public void setTransactionId(int transactionId) {
this.transactionId = transactionId;
}
public String getAmount() {
return amount;
}
public void setAmount(String amount) {
this.amount = amount;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getSubText() {
return subText;
}
public void setSubText(String subText) {
this.subText = subText;
}
}
When I execute my app, I am not able to see the recycler with the cards. Can someone help me where I am going wrong. Just point me in the right direction.
Thanks in advance.

You wrote findViewById to the Activity class. However RecyclerView is not in your activity_home.xml, it is in nested layout.
Try defining the included layout and apply findViewById on that view, or simply define RecyclerView in your activity_home.xml
Why So?
Activity.findViewById(int id) method finds the id inside that particular Activity's layout. If you have nested layout, for example, like this activity_home.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
...
<include
android:id="#+id/view_card_list_fav_transact"
layout="#layout/card_list_fav_transact"/>
</android.support.v4.widget.DrawerLayout>
and your card_list_fav_transact.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:scrollbars="vertical"/>
</LinearLayout>
Code inside your Activity will be
View includedView = findViewById(R.id.view_card_list_favt_transact);
RecyclerView rv = includedView.findViewById(R.id.my_recycler_view);
And you are all set!

Related

Fragment is occupying full screen in activity

I am stuck at this point where I am adding a Fragment in a NavigationDrawer activity. When the activity displays the fragment, the fragment bumps up the whole screen as shown in the image below:
The expected behaviour is as shown in the image below.
I am using databinding with a RecyclerView. StockListItem is the POJO class used for accessing data in RecyclerView and stock_list_item_layout is the layout used for displaying list items in RecylerView.
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
private RecyclerViewAdapter adapter;
DrawerLayout drawer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open,
R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView)
findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
getSupportFragmentManager().beginTransaction().add(R.id.flContainer,new
WatchlistFragment()).commit();
}
}
public class WatchlistFragment extends Fragment {
private FragmentWatchlistBinding watchlistBinding;
private RecyclerViewAdapter adapter;
private List<StockListItem> lstStockItems = new ArrayList<>();
public WatchlistFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_watchlist, container,
false);
Toast.makeText(getActivity(), "Reached WatchlistFragment.",
Toast.LENGTH_SHORT).show();
watchlistBinding =
DataBindingUtil.setContentView(getActivity(),R.layout.fragment_watchlist);
watchlistBinding.rvMyRecyclerView.setLayoutManager(new
LinearLayoutManager(getActivity()));
watchlistBinding.rvMyRecyclerView.setHasFixedSize(false);
lstStockItems.add(new StockListItem("Vedanta
Ltd","174.45","+5.35","+3.45"));
lstStockItems.add(new StockListItem("Eicher Motors
Ltd","19974.45","+545.35","+13.45"));
lstStockItems.add(new StockListItem("Adani Green Energy
Ltd","34.45","+5.35","+3.45"));
lstStockItems.add(new StockListItem("Federal Bank
Ltd","84.45","+5.35","+3.45"));
lstStockItems.add(new StockListItem("Hindustan Zinc
Ltd","274.45","+5.35","+3.45"));
lstStockItems.add(new StockListItem("Indian Oil Corporation
Ltd","154.45","+5.35","+3.45"));
lstStockItems.add(new StockListItem("Hindustan Petroleum Corporation
Ltd","154.45","+5.35","+3.45"));
lstStockItems.add(new StockListItem("ITC
Ltd","274.45","+5.35","+3.45"));
adapter = new RecyclerViewAdapter(getActivity(),lstStockItems);
watchlistBinding.rvMyRecyclerView.setAdapter(adapter);
return v;
}}
This is what my fragment_watchlist.xml looks like.
<?xml version="1.0" encoding="utf-8"?>
<layout >
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".WatchlistFragment"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<TextView
android:text="Watchlist"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView
android:id="#+id/rvMyRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</FrameLayout>
</layout>
public class RecyclerViewAdapter extends
RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {
private Context ctx;
private List<StockListItem> lstUsers = new ArrayList<>();
public RecyclerViewAdapter(Context ctx, List<StockListItem> lstUsers) {
this.ctx = ctx;
this.lstUsers = lstUsers;
}
#NonNull
#Override
public RecyclerViewAdapter.MyViewHolder onCreateViewHolder(#NonNull
ViewGroup viewGroup, int i) {
StockListItemLayoutBinding stockListItemLayoutBinding =
DataBindingUtil.inflate(LayoutInflater.from(viewGroup.getContext()),
R.layout.stock_list_item_layout,viewGroup,false);
MyViewHolder myViewHolder = new
MyViewHolder(stockListItemLayoutBinding);
return myViewHolder;
}
#Override
public void onBindViewHolder(#NonNull RecyclerViewAdapter.MyViewHolder
viewHolder, int i) {
StockListItem stockListItem = lstUsers.get(i);
viewHolder.stockListItemLayoutBinding.setStock(stockListItem);
}
#Override
public int getItemCount() {
return lstUsers.size();
}
public static class MyViewHolder extends RecyclerView.ViewHolder
{
StockListItemLayoutBinding stockListItemLayoutBinding;
public MyViewHolder(#NonNull StockListItemLayoutBinding
stockListItemLayoutBinding) {
super(stockListItemLayoutBinding.getRoot());
this.stockListItemLayoutBinding = stockListItemLayoutBinding;
}
}
}
public class StockListItem
{
private String StockName;
private String StockPrice;
private String StockPriceChange;
private String StockPriceChangePercent;
public String getStockPriceChange() {
return StockPriceChange;
}
public String getStockPriceChangePercent() {
return StockPriceChangePercent;
}
public void setStockPriceChange(String stockPriceChange) {
StockPriceChange = stockPriceChange;
}
public void setStockPriceChangePercent(String stockPriceChangePercent) {
StockPriceChangePercent = stockPriceChangePercent;
}
public void setStockName(String stockName) {
StockName = stockName;
}
public void setStockPrice(String stockPrice) {
StockPrice = stockPrice;
}
public String getStockName() {
return StockName;
}
public String getStockPrice() {
return StockPrice;
}
public StockListItem(String stockName, String stockPrice, String
stockPriceChange, String stockPriceChangePercent) {
this.StockName = stockName;
this.StockPrice = stockPrice;
this.StockPriceChange = stockPriceChange;
this.StockPriceChangePercent = stockPriceChangePercent;
}
}
This is what stock_list_item_layout.xml looks like.
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
type="com.example.mvp1stockmeter.StockListItem"
name="Stock"/>
</data>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?attr/selectableItemBackground"
android:layout_margin="4dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tvStockName"
android:layout_margin="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#{Stock.StockName}"
android:layout_alignParentLeft="true"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="right">
<TextView
android:id="#+id/tvStockPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:text="#{Stock.StockPrice}"
android:textSize="20sp"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tvStockPriceChange"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:text="#{Stock.StockPriceChange}"
android:textSize="16sp"
android:layout_alignParentRight="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:text="("
android:textSize="16sp"/>
<TextView
android:id="#+id/tvStockPriceChangePercent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="#{Stock.StockPriceChangePercent}"
android:textSize="16sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:text="%)"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</layout>
This is what my activity_main.xml looks like. -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/app_bar_main"
android:orientation="vertical">
<FrameLayout
android:visibility="visible"
android:id="#+id/flContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</FrameLayout>
</LinearLayout>
app_bar_main.xml layout file looks like-
<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=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
The content_main.xml file looks like this-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/app_bar_main"
android:orientation="vertical">
<FrameLayout
android:visibility="visible"
android:id="#+id/flContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize">
</FrameLayout>
</LinearLayout>
This is how my nav_header_main.xml file looks like-
<?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:layout_width="match_parent"
android:layout_height="#dimen/nav_header_height"
android:background="#drawable/side_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/app_name"
android:paddingTop="#dimen/nav_header_vertical_spacing"
app:srcCompat="#mipmap/ic_launcher_round" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/nav_header_vertical_spacing"
android:text="#string/app_name"
android:textAppearance="#style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/website" />
</LinearLayout>
This is how my activity_main_drawer.xm file looks like-
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_watchlist"
android:icon="#drawable/ic_menu_camera"
android:title="Watchlist" />
<item
android:id="#+id/nav_profile"
android:icon="#drawable/ic_menu_manage"
android:title="Profile" />
<item
android:id="#+id/nav_suggestions_or_complaints"
android:icon="#drawable/ic_menu_manage"
android:title="Suggestions / Complaints" />
<item
android:id="#+id/nav_upcoming_features"
android:icon="#drawable/ic_menu_manage"
android:title="Upcoming Features" />
</group>
</menu>
This is how my main.xml file looks like -
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="never" />
</menu>
Just add android:layout_marginTop="?attr/actionBarSize" in your activity_main's FrameLayout, like this:
<FrameLayout
android:visibility="visible"
android:layout_marginTop="?attr/actionBarSize"
android:id="#+id/flContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</FrameLayout>

Recycler view is in black colour

ScreenShot of the screen from Tab(Marshmallow)
The recycler view with cardview items is showing in black. Also I cannot change background colour. But when running in android emulator it seems fine, the background is default in white color. What could i had done wrong
public class MainActivity extends AppCompatActivity {
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mRecycleAdapter;
private RecyclerView.LayoutManager mLayoutManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRecyclerView = (RecyclerView)findViewById(R.id.recyclerviewss);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(getApplicationContext());
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mRecycleAdapter = new RentalAdapter(getApplicationContext(), 75);
mRecyclerView.setAdapter(mRecycleAdapter);
}
}
class RentalAdapter extends RecyclerView.Adapter<RentalAdapter.RentalAdapterHolder> {
private final LayoutInflater mLayoutInflater;
private Context mContext;
private int mListCount;
int lastPosition = -1;
RentalAdapter(Context context, int listCount) {
mLayoutInflater = LayoutInflater.from(context);
mContext = context;
mListCount = listCount;
}
#Override
public RentalAdapterHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = mLayoutInflater.inflate(R.layout.sampcard, parent, false);
RentalAdapter.RentalAdapterHolder rentalHolder = new RentalAdapterHolder(view);
return rentalHolder;
}
#Override
public void onBindViewHolder(final RentalAdapterHolder holder, int position) {
holder.mTextView.setText("sample");
}
#Override
public int getItemCount() {
return 75;
}
class RentalAdapterHolder extends RecyclerView.ViewHolder {
private TextView mTextView;
private ImageView mImageView;
public RentalAdapterHolder(View itemView) {
super(itemView);
mTextView = (TextView)itemView.findViewById(R.id.info_text);
}
}
}
sampcard.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="50dp"
card_view:cardCornerRadius="4dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ASKDNAKJDHN"
android:id="#+id/info_text"/>
</android.support.v7.widget.CardView>
</LinearLayout>
activity_main.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="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/recyclerviewss"
/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_gravity="center"
card_view:background_color="#color/white"
android:layout_width="match_parent"
android:layout_height="50dp"
card_view:cardCornerRadius="4dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:gravity="left|center_vertical"
android:paddingLeft="20dp"
android:layout_height="match_parent"
android:text="ASKDNAKJDHN"
android:id="#+id/info_text"/>
</android.support.v7.widget.CardView>
</LinearLayout>
Try this code.
Just add a background attribute android:background="#android:color/white" to your sampcard.xml layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="50dp"
card_view:cardCornerRadius="4dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ASKDNAKJDHN"
android:id="#+id/info_text"/>
</android.support.v7.widget.CardView>
</LinearLayout>
I encountered the same problem and got it resolved by applying Background color to the root view in XML file which in you case is Recycler view.
Add this in your Recycler View XML code :
android:background = "#ffffff"

RecyclerView not displaying last item but is calling onBindView

I am trying a list of items using RecyclerView , everything works fine but the last item is not being displayed! The length of the list is 2 and onBindView is called twice and the when I used Log to print the items it aslo prints the last item. So the list is fine but the RecyclerView is not displaying it.
This is my code RecyclerView Adapter:
public class ModuleList extends RecyclerView.Adapter<ModuleList.ViewHolder> {
private List<Module> moduleList;
public ModuleList(List<Module> moduleList){
this.moduleList = moduleList;
}
public ModuleList(){
this.moduleList = new ArrayList<>();
}
public List<Module> getModuleList() {
return moduleList;
}
public void setModuleList(List<Module> moduleList) {
this.moduleList = moduleList;
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_modules,parent,false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
Module module = moduleList.get(position);
// function is called twice and the all items are logged works fine
Log.d("ALL",module.getModuleName());
Log.d("ALL", String.valueOf(module.getNumberOfLevels()));
holder.moduleName.setText(String.valueOf(module.getModuleName()));
holder.numberOfLevels.setText(String.valueOf(module.getNumberOfLevels()));
}
#Override
public int getItemCount() {
//size is 2
return moduleList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
public TextView moduleName;
public TextView numberOfLevels;
public ViewHolder(View itemView) {
super(itemView);
moduleName = (TextView) itemView.findViewById(R.id.list_module_name);
numberOfLevels = (TextView) itemView.findViewById(R.id.list_no_of_levels);
}
}
}
This is my xml where recyclerview is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/all_modules_list"
android:scrollbars="vertical"
/>
</LinearLayout>
This is my xml where RecyclerView Fragment is displayed:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_screen"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main_screen_container"
android:orientation="vertical"
>
<android.support.v7.widget.Toolbar
android:id="#+id/main_screen_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/fragment_container">
</FrameLayout>
</LinearLayout>
<ListView
android:layout_width="240dp"
android:layout_height="match_parent"
android:id="#+id/navigation_items"
android:layout_gravity="start"
android:background="#android:color/white"
>
</ListView>
</android.support.v4.widget.DrawerLayout>
Edit:list_module.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/list_module_name"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/list_no_of_levels"
/>
</LinearLayout>
Hey can you try the solution below?
Change this in the list_module.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="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/list_module_name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/list_no_of_levels"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
I have replaced match_parent to wrap_content to parent layout.

CardView - mysterious gaps emerge when scrolling upwards

I finally managed to get the card view to look just like I want it.
I use a GridLayoutManager with two columns to display cards with a thumbnail. Everything nice and working so far.
Anyway, once I scroll up, everything blows up. Large gaps (the size of a card itself) emerge between each row, now I every second row will be an empty one. I do not understand how that would possibly happen. I don't have any problem while scrolling down, but even one inch back up and everything is in pieces (so to speak).
Maybe some can see what is wrong with the layout.
actvivity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:titleTextColor="#android:color/primary_text_dark" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
tools:context=".view.MainActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/series_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:scrollbars="vertical"
/>
</RelativeLayout>
card.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_width="160dp"
android:layout_height="270dp"
android:layout_gravity="center"
android:layout_margin="5dp"
android:elevation="3dp"
app:cardUseCompatPadding="true"
app:cardCornerRadius="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
/>
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/thumbnail"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:textColor="#color/colorSeriesTitle"
android:textSize="15dp" />
<TextView
android:id="#+id/rating"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textSize="12dp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
Adapter
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder>{
private List<Stuff> stuff;
private Callback callback;
private Context context;
public MyAdapter(Context context) {
this.context = context;
stuff = Collections.emptyList();
}
public MyAdapter(List<Stuff> stuff) {
this.stuff = stuff;
}
public void setStuff(List<Stuff> stuff) {
this.stuff = stuff;
}
public void setCallback(Callback callback) {
this.callback = callback;
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
public Stuff stuff;
public View contentLayout;
public ImageView thumbnailImageView;
public TextView titleTextView;
public TextView ratingTextView;
public MyViewHolder(View itemView) {
super(itemView);
contentLayout = itemView.findViewById(R.id.layout_content);
thumbnailImageView = (ImageView) itemView.findViewById(R.id.thumbnail);
titleTextView = (TextView) itemView.findViewById(R.id.title);
ratingTextView = (TextView) itemView.findViewById(R.id.rating);
}
}
public interface Callback {
void onItemClick(Series series);
}
#Override
public SeriesViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
final View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.series_card, parent, false);
final MyViewHolderviewHolder = new MyViewHolder(itemView);
viewHolder.contentLayout.setOnClickListener(view -> {
if (callback != null) {
callback.onItemClick(viewHolder.series);
}
});
return viewHolder;
}
#Override
public void onBindViewHolder(MyViewHolderholder, int position) {
Stuff stuff = this.stuff.get(position);
holder.stuff = stuff;
holder.titleTextView.setText(stuff.getName())
holder.ratingTextView.setText(stuff.getStatus());
Picasso.with(context)
.load(stuff.getSomeImageURL())
.fit()
.centerCrop()
.into(holder.thumbnailImageView);
}
#Override
public int getItemCount() {
return stuff.size();
}
card.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
Changing the layout_height to wrap_content fixed the problem.

Android toolbar is covering a fragment

I have 2 layouts in an app that are being covered by the toolbar. In each layout I've tried using android:layout_below="#id/app_bar_layout or android:layout_below="#id/toolbar, with no luck. How can I fix this?
The recycler view is called by a touch on an menu item and, inflated by rv adpater and view holder classes. So far, I have no other problems with the app except the toolbar covering the views.
<?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"
android:fitsSystemWindows="true"
tools:context="com.example.aaron.walkingtourtest09feb.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/app_bar_layout"
android:theme="#android:style/Theme.Material">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:elevation="4dp"
app:popupTheme="#style/AppTheme.PopupOverlay"
android:background="#607D8B"/>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main"/>
</android.support.design.widget.CoordinatorLayout>
content_main.xml:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar"
tools:context="com.example.test09feb.MainActivity"
tools:showIn="#layout/app_bar_main"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<fragment
android:id="#+id/listFragment"
android:tag="unique_tag"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.example.test09feb.MainActivity$ExampleFragment" >
</fragment>
Recyclerview_activity.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/cardview_light_background"
android:animateLayoutChanges="true"
android:padding="6dp">
<android.support.v7.widget.RecyclerView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/rv">
</android.support.v7.widget.RecyclerView>
cards.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/cv"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:id="#+id/card_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="#EEEEEE"
android:orientation="vertical"
android:padding="0dp">
<ImageView
android:id="#+id/subject_photo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"/>
<TextView
android:id="#+id/subject_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/subject_photo"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:textColor="#android:color/black"
android:textSize="16sp"/>
<TextView
android:id="#+id/subject_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/subject_name"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textColor="#777777"
/>
<Button
android:id="#+id/card_button_left"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/subject_text"
android:layout_toLeftOf="#+id/card_button_right"
android:text="#string/watch"
/>
<Button
android:id="#id/card_button_right"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/subject_text"
android:text="#string/read"/>
<TextView
android:id="#+id/expanded_subject_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/card_button_right"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textColor="#777777"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
RVAdapter:
public class RVAdapter extends RecyclerView.Adapter<RVAdapter.SubjectViewHolder> {
List<Subject> subjects;
static SubjectViewHolder svh;
View v = null;
Context cxt;
private static MyListener listener;
public interface MyListener {
void onClick(View itemView, int viewPosition);
}
RVAdapter(List<Subject> subjects, Context cxt) {
this.subjects = subjects;
this.cxt = cxt;
}
public void setOnClickListener(MyListener listener) {
this.listener = listener;
}
#Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
#Override
public SubjectViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.cards, viewGroup, false);
svh = new SubjectViewHolder(v);
return svh;
}
String[] localLinks = {
"http://192.168.11.111:8000/pic1.png",
"http://192.168.11.111:8000/pic2.jpg",
"http://192.168.11.111:8000/pic3.png",
"http://192.168.11.111:8000/pic4.jpg",
"http://192.168.11.111:8000/pic5.png",
"http://192.168.11.111:8000/pic6.jpg",
"http://192.168.11.111:8000/pic7.png",
"http://192.168.11.111:8000/pic8.jpg",
"http://192.168.11.111:8000/pic9.png",
"http://192.168.11.111:8000/pic10.jpg",
"http://192.168.11.111:8000/pic11.png",
"http://192.168.11.111:8000/pic12.png",
"http://192.168.11.111:8000/pic13.png",
"http://192.168.11.111:8000/pic14.png",
};
#Override
public void onBindViewHolder(SubjectViewHolder subjectViewHolder, int i) {
subjectViewHolder.subjectName.setText(subjects.get(i).subjectName);
subjectViewHolder.subjectText.setText(subjects.get(i).subjectText);
Picasso.with(cxt).load(localLinks[i]).into(subjectViewHolder.subjectPhoto);
subjectViewHolder.expandedSubjectText.setText(subjects.get(i).expandedSubjectText);
subjectViewHolder.expandedSubjectText.setVisibility(View.GONE);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public int getItemCount() {
return subjects.size();
}
public static class SubjectViewHolder extends RecyclerView.ViewHolder {
CardView cv;
TextView subjectName;
TextView subjectText;
TextView expandedSubjectText;
ImageView subjectPhoto;
Button leftButton;
Button rightButton;
SubjectViewHolder(final View itemView) {
super(itemView);
cv = (CardView) itemView.findViewById(R.id.cv);
subjectName = (TextView) itemView.findViewById(R.id.subject_name);
subjectText = (TextView) itemView.findViewById(R.id.subject_text);
expandedSubjectText = (TextView) itemView.findViewById(R.id.expanded_subject_text);
subjectPhoto = (ImageView) itemView.findViewById(R.id.subject_photo);
leftButton = (Button) itemView.findViewById(R.id.card_button_left);
rightButton = (Button) itemView.findViewById(R.id.card_button_right);
rightButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (expandedSubjectText.getVisibility() == View.GONE) {
expandedSubjectText.setVisibility(View.VISIBLE);
} else {
expandedSubjectText.setVisibility(View.GONE);
}
// Triggers click upwards to the adapter on click
if (listener != null)
v.findViewById(R.id.card_container);
listener.onClick(rightButton, svh.getAdapterPosition());
}
});
leftButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Triggers click upwards to the adapter on click
if (listener != null)
listener.onClick(leftButton, svh.getAdapterPosition());
}
});
}
}}
result of adding appbar_scrolling_view_behavior as suggested. A blank bar covers the textview that has just animated itself visible.
You have to add following attribute to the parent view in content_main.xml
app:layout_behavior="#string/appbar_scrolling_view_behavior"
Like this:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.test09feb.MainActivity"
tools:showIn="#layout/app_bar_main"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</FrameLayout>
Your Toolbars height is defined by: android:layout_height="?attr/actionBarSize"
so I added a top margin with those values to the list view:
android:layout_marginTop="?attr/actionBarSize"
Worked for me in the app I'm working on.

Categories

Resources