Jeyaseelan
Jeyaseelan

Reputation: 661

Cardview is not working properly in Devices lower than Lollipop

This screen shot is taken in Marshmallow

enter image description here

This one is taken in jelly bean in this the image is not shown and in the menus the text is not visible

enter image description here

I have a layout with Cardview as the parent view.

It consists of images and text. Now the layout works fine on devices with Android M and above but in lower versions (like Jellybean ) the images are not shown properly.They turn small and are not matching the card view fully

Here's my layout XML file:

<android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="3dp"
            app:cardPreventCornerOverlap="false"
            android:elevation="2dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:orientation="horizontal">

                <android.support.v7.widget.CardView
                    android:layout_width="80dp"
                    android:layout_height="80dp">

                    <ImageView
                        android:id="@+id/home_news_image"
                        android:layout_width="80dp"
                        android:layout_height="80dp"
                        android:layout_gravity="center_vertical"
                        android:scaleType="centerCrop"
                        android:src="@drawable/jesus" />
                </android.support.v7.widget.CardView>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:gravity="center_vertical"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/home_title_parish_news"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="5dp"
                        android:paddingLeft="1dp"
                        android:text="Christmas Celebration"
                        android:textSize="14dp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/home_short_description"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:ellipsize="end"
                        android:maxLines="1"
                        android:padding="3dp"
                        android:text="hi this is to tell thlkdsa asdsag slk sg sdg sdgjs gsd gsg jglsgja gasjggjasg asgjasgj sgjasg g g"
                        android:textSize="12dp" />

                    <TextView
                        android:id="@+id/home_date_published"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="10dp"
                        android:gravity="right|bottom"
                        android:padding="3dp"
                        android:text="10/10/2010"
                        android:textSize="8dp" />
                </LinearLayout>
            </LinearLayout>
        </android.support.v7.widget.CardView>

This is the adapter where i initialize my layout and views

public class MenuAdapter extends BaseAdapter {

    Context mContext;
    ArrayList<MenuModel> list;
    String img;


    public MenuAdapter(Context c, ArrayList<MenuModel> list) {
        mContext = c;
        this.list = list;

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        View grid;
        LayoutInflater inflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (view == null) {
            grid = inflater.inflate(R.layout.home_grid_menu, null);
            TextView textView = (TextView) grid.findViewById(R.id.home_grid_text);
            ImageView imageView = (ImageView) grid.findViewById(R.id.home_grid_image);
            textView.setText(list.get(i).getMenuName());
            imageView.setImageResource(list.get(i).getMenuImage());

        } else {
            grid = (View) view;
        }

        return grid;
    }
}

Also if I place a text under an image the text is not visible.

Please suggest me how to go about it.

I hope now i will get some solution

Upvotes: 0

Views: 647

Answers (2)

Muhammad Tufail
Muhammad Tufail

Reputation: 336

First you need to read the file from the assets folder in android here is the example how to read html file from assets folder

InoutInputStream is = getAssets().open("yourfile.html");
int size = is.available();

byte[] buffer = new byte[size];
is.read(buffer);
is.close();
String str = new String(buffer);

You have the html file in the String now your need to get text from the html file using HTML.fromhtml.

String htmltext=Html.fromHtml(Html.fromHtml(str).toString())

If you want to share the html text then you can share the text using android intent

    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
    sharingIntent.setType("text/plain");
    sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Sharing html Text");
    sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, htmltext);
    startActivity(Intent.createChooser(sharingIntent, "Select"));

Upvotes: 2

Umar Hussain
Umar Hussain

Reputation: 3527

card views works properly starting lollipop, they have backward support but rendering is usually not the same.

For the specific issue please attach images of both screen

Upvotes: 0

Related Questions