I am developing an Android app. In my app, I am using snackbar with custom view. My custom view has only child view. That is an image view. Showing custom view with snack bar is ok. But the problem is with the sizing the ImageView in the snack bar. I want to set it match parent for with. But width is not match to the width of snackbar. Please see my scenario below.
This is my custom view layout for snack bar
<?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">
<ImageView
android:scaleType="centerCrop"
android:id="@+id/snackbar_ad_image"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
This is how I show snack bar in activity
private void showSnackbarAd(View view,Ad ad)
{
final Snackbar snackbar = Snackbar.make(view,"",Snackbar.LENGTH_LONG);
Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout)snackbar.getView();
TextView textView = (TextView) layout.findViewById(android.support.design.R.id.snackbar_text);
textView.setVisibility(View.INVISIBLE);
View snackView = getLayoutInflater().inflate(R.layout.snack_bar_ad,null);
ImageView imageView = (ImageView)snackView.findViewById(R.id.snackbar_ad_image);
Picasso.with(getBaseContext()).load(ad.getImageUrl()).into(imageView);
layout.addView(snackView, 0);
snackbar.show();
}
What I want is I want ImageView same width width snack bar. But my code is not working.
This is what I got.
How can I make that ImageView as the same width with Snackbar and fit in snackbar?