Android - CardView give strange behaviour

Mina Fawzy

here is my situation I have list view (RecyclerView)

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/coordiatelayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/dark_gray">

    <TextView
        android:id="@+id/reload"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@string/reload"
        android:visibility="gone" />

    <ProgressBar
        android:id="@+id/progressbar"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:visibility="gone"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/questionlist"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/FloatingView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="15dp"
        android:clickable="true"
        app:layout_anchor="@id/questionlist"
        app:layout_anchorGravity="right|bottom|end"
        android:src="@drawable/ic_add_circle_outline_24dp"
         />


</android.support.design.widget.CoordinatorLayout>

I maintain this recycle view with adapter

public class ListViewAdapter extends RecyclerView.Adapter<ListViewAdapter.ViewHolder> {

    private Context _Context;

    private List<QuestionItem> Questions = new ArrayList<>();
    private API api;
    private int num;
    private int lastPosition = -1;
    public static final String BASE_POST_URl = "http://la3nyk.com/upload/";

    public ListViewAdapter(Context context, List<QuestionItem> Questions) {
        this._Context = context;
        this.Questions = Questions;
        api = new API(context);
    }

    public ListViewAdapter(Context context, List<QuestionItem> Questions,
            int num) {
        this._Context = context;
        this.Questions = Questions;
        this.num = num;
        api = new API(context);
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(_Context);
        View itemView = inflater.inflate(R.layout.questions, null);
        return new ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Typeface tf = Typeface.createFromAsset(_Context.getAssets(),
                "fonts/GE_SS_Two_Bold.otf");
        Typeface tfreg = Typeface.createFromAsset(_Context.getAssets(),
                "fonts/GE_SS_Two_Light.otf");

        ImageLoader _ImageLoader = MySingleton.getInstance(_Context).getmImageLoader();

        holder.imageView.setImageUrl( BASE_POST_URl + Questions.get(position).getQue_image_url(), _ImageLoader);
        holder.username.setTypeface(tf);
        holder.username.setText(Questions.get(position).user.username);
        holder.desc.setText(Questions.get(position).Que_Content);
        holder.desc.setTypeface(tfreg);
        holder.Date.setTypeface(tfreg);
        holder.Category.setText(Questions.get(position).category);
        holder.AnswersCount.setTypeface(tfreg);
        holder.Date.setText(Questions.get(position).Que_Date);
        holder.AnswersCount.setText(Questions.get(position).answers.size() + " " + _Context.getResources().getString(R.string.answers));
        holder.AnswersCount.setVisibility(View.VISIBLE);



//      if (num == 1)
//          Questions.get(pos).user.userimageURL = api
//                  .getSetting(AppConstants.TAG_user_photo);
//
//
//
//      if (Questions.get(pos).Que_image_url != null) {
//          if (!Questions.get(pos).Que_image_url.contentEquals("")) {
//              post_img.setVisibility(View.VISIBLE);
//              //loader.DisplayImage(Questions.get(pos).Que_image_url, post_img,
//              //      post_img_pro, -1);
//          }
//      }
//
//

         //if (num == 1) {
         //arrow.setImageResource(R.drawable.p_data_7);}
         //arrow.setVisibility(View.VISIBLE);

//      Animation animation = null;
//       animation = AnimationUtils.loadAnimation(_Context,
//               R.anim.up_from_bottom);
//       animation.setDuration(500);
//          view.setAnimation(animation);
//            animation = null;
//
//      Animation animation = AnimationUtils.loadAnimation(_Context,
//              (pos > lastPosition) ? R.anim.up_from_bottom
//                      : R.anim.down_from_top);
//      view.startAnimation(animation);
//      lastPosition = pos;

    }

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

    @Override
    public int getItemCount() {
        return Questions.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        protected NetworkImageView imageView , post_img;
        protected TextView desc , Category ,username ,Date ,AnswersCount;
        protected ProgressBar userimageprog ,post_img_pro;
        protected ImageView arrow;

        public ViewHolder(View itemView) {
            super(itemView);
             imageView = (NetworkImageView) itemView.findViewById(R.id.ques_user_img);
             desc = (TextView) itemView.findViewById(R.id.ques_content);
             Category = (TextView) itemView.findViewById(R.id.category);
             post_img = (NetworkImageView) itemView.findViewById(R.id.post_img);
             userimageprog = (ProgressBar) itemView.findViewById(R.id.userimgae_prog);
             post_img_pro = (ProgressBar) itemView.findViewById(R.id.post_img_pro);
             username = (TextView) itemView.findViewById(R.id.username_ques);
             Date = (TextView) itemView.findViewById(R.id.date);
             AnswersCount = (TextView) itemView.findViewById(R.id.answers_con);
            arrow = (ImageView) itemView.findViewById(R.id.imageView1);

        }
    }
}

CardView xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:cardview="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    cardview:cardBackgroundColor="@android:color/white"
    android:layout_gravity="center_horizontal"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    cardview:cardCornerRadius="5dp"
    cardview:cardElevation="2dp"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        android:orientation="vertical"
        >

        <TextView
            android:id="@+id/category"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@color/blue"
            android:padding="10dp"
            android:text="TextView"
            android:textColor="@android:color/white" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal" >

            <FrameLayout
                android:id="@+id/frameLayout1"
                android:layout_width="60dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginBottom="10dp"
                android:layout_marginLeft="4dp"
                android:layout_marginRight="4dp"
                android:layout_marginTop="10dp" >

                <com.android.volley.toolbox.NetworkImageView
                    android:id="@+id/ques_user_img"
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:src="@drawable/profile" />

                <ProgressBar
                    android:id="@+id/userimgae_prog"
                    style="?android:attr/progressBarStyleSmall"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:visibility="gone" />


            </FrameLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/username_ques"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="Asmaa Samir"
                    android:textColor="@android:color/black"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/date"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:layout_marginTop="3dp"
                    android:textColor="@android:color/black"
                    android:text="2 days ago" />
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/ques_content"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_margin="4dp"
                android:text="ماهى اسباب ضعف الرؤيه أمام الحاسوب؟"
                android:textColor="@android:color/black"
                android:textStyle="bold" />
        </LinearLayout>

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_gravity="center"
            android:src="@drawable/qustion_8"
            android:visibility="gone" />

        <com.android.volley.toolbox.NetworkImageView
            android:id="@+id/post_img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:src="@drawable/ic_launcher"
            android:visibility="gone" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_gravity="right"
            android:layout_weight="1"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/answers_con"
                android:visibility="gone"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:layout_weight="1"
                android:text="32 إجابه" />
        </LinearLayout>
    </LinearLayout>


</android.support.v7.widget.CardView>

here is my screenshot , what is my question ?

1- I got warp content cardview as appear in image.

2- my floating button appear down when view start load.

enter image description here

Nitin Mesta

In the createViewHolder method of Adapter change this

        View itemView = inflater.inflate(R.layout.questions, null);

to

  View itemView = inflater.inflate(R.layout.questions, parent,false);

We need to attach this card to the parent recyclerview to inherit its attribute

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Strange behaviour of size utility

Strange Goroutines Behaviour

Set a PasswordField to secureTextEntry give me a strange behaviour

MATLAB subs(): Strange behaviour

Strange behaviour Constraint Layout Animation on differente Android versions

Strange looping behaviour in javascript

Android Jetpack Navigation nested tab backward navigation strange behaviour

Struct and bitfield strange behaviour

Matplotlib: plotting string values give strange behaviour

Android SQLite select statement strange behaviour

Android - Very strange behaviour with GridView

Android Video Strange Behaviour on amazon TV

Strange clientHeight behaviour for image

OPENGL ES 2.0. Android. Strange behaviour of depth buffer

Strange behaviour in installation of PHPUnit

Android drawable resources strange behaviour

Variant from android-autofittextview library : scaling makes strange behaviour

Strange onClick highlighting for CardView

Strange behaviour replacing fragments in Android

Strange debugger behaviour in Android studio when debugging an Async task

UIView strange behaviour with BOOL

PHPUnit withConsecutive strange behaviour

Strange date behaviour with MongoDB

Strange behaviour of unit test in Android

Strange behaviour with Android Activity Lifecycle when connecting to Google API Client

Strange intellisense tab behaviour

Really strange behaviour in android firebaseRecycleAdapter checkbox

Android studio strange behaviour with some files appearing different than how they are

Activity still staying over previous activity in Android Strange Behaviour

TOP Ranking

HotTag

Archive