Fragment doesn't respect match parent height when having listview row item has hidden view in it
<p>I am having a weird issue in my app. In one of my app activity I am inflating three fragments in it with tabs. Everything works fine.
In the fragment in which I am having problem, I have listview which is inflated using adapter and data fro web service. This also works well. Now the problem is this the row which is inflated in adapter, has a hidden view which has <code>visibility=gone</code> in xml. On tap of imageview from that row I make that layout visible through java code. The problem is layout doesn't become visible on tap. <strong>I have even set breakpoint on the onClickListener of imageview</strong> and it does execute the line which changes the visibility from gone to visible. I am unable to understand what is causing this issue as I am using the same row xml with same data in other screen and there it is working perfectly. </p>

<p><strong>UPDATE</strong></p>

<p>I got to know what's causing this issue but don't know how to solve this. In my activity I am having three fragments. The view that I provided for fragment(in which fragment will be inflated) is causing main problem. I have set height width to match parent but it is not taking match parent height. If the fragment just includes normal views like textview, imageview then also fragment is shown properly.But the problem is if fragment consists of listview, then it only takes height of the custom row that is supplied to the listview. I am able to scroll complete listview in that space. 
I don't understand what is causing this behaviour.
My Updated code.</p>

<p>Main layout xml</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;

&lt;LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    &lt;include layout="@layout/header_1" /&gt;



&lt;LinearLayout
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="#000"
    android:weightSum="3"
    android:orientation="horizontal"&gt;
    &lt;LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:weightSum="1"
        android:orientation="horizontal"
        android:id="@+id/lin_birds"&gt;
        &lt;TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="@string/aves"
            android:textColor="#ffffff"
            android:gravity="center"
            android:layout_gravity="center"
            android:layout_weight="0.99"
            android:id="@+id/fragment_aves"/&gt;
        &lt;View
            android:layout_width="0dp"
            android:layout_height="30dp"
            android:layout_weight="0.01"
            android:background="#ffffff"
            android:layout_marginTop="10dp"/&gt;
    &lt;/LinearLayout&gt;
    &lt;LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:weightSum="1"
        android:orientation="horizontal"&gt;
        &lt;TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="@string/routes"
            android:textColor="#ffffff"
            android:gravity="center"
            android:layout_gravity="center"
            android:layout_weight="0.99"
            android:id="@+id/fragment_routes"/&gt;
        &lt;View
            android:layout_width="0dp"
            android:layout_height="30dp"
            android:layout_weight="0.01"
            android:background="#ffffff"
            android:layout_marginTop="10dp"/&gt;
    &lt;/LinearLayout&gt;
    &lt;LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal"&gt;
        &lt;TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="@string/information"
            android:textColor="#ffffff"
            android:gravity="center"
            android:layout_gravity="center"
            android:id="@+id/fragment_information"/&gt;

    &lt;/LinearLayout&gt;
&lt;/LinearLayout&gt;

        &lt;LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"&gt;
    &lt;FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/frame_details" /&gt;

    &lt;/LinearLayout&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p>Main activity java code</p>

<pre><code>    public class ActivityRoutesDetails extends AppCompatActivity {
    RelativeLayout rel_back;
    TextView tv_title,tv_information,tv_routes,fragment_aves;
    RoutesDataBean routesDataBean;
    LinearLayout frame;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.routes_detail);
        tv_title= (TextView)findViewById(R.id.tv_title);
        tv_information= (TextView) findViewById(R.id.fragment_information);
        tv_routes= (TextView) findViewById(R.id.fragment_routes);
        fragment_aves= (TextView) findViewById(R.id.fragment_aves);
//        frame= (LinearLayout) findViewById(R.id.frame_details);
        routesDataBean= (RoutesDataBean)getIntent().getSerializableExtra("data");
        tv_title.setText(routesDataBean.getDescrip1());

        Fragment fragment=new FragmentRouteInside();
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.add(R.id.frame_details, fragment);
        fragmentTransaction.commit();
        fragment_aves.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Fragment fragmentBirds=new FragmentRouteBirds();
                FragmentManager fragmentManager = getSupportFragmentManager();
                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                fragmentTransaction.replace(R.id.frame_details, fragmentBirds);
                fragmentTransaction.commit();
            }
        });

        tv_information.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Fragment fragmentRouteInformation = new FragmentRouteInformation();
                FragmentManager fragmentManager = getSupportFragmentManager();
                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                fragmentTransaction.replace(R.id.frame_details, fragmentRouteInformation);
                fragmentTransaction.commit();
            }
        });
        tv_routes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Fragment fragment=new FragmentRouteInside();
                FragmentManager fragmentManager = getSupportFragmentManager();
                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                fragmentTransaction.replace(R.id.frame_details, fragment);
                fragmentTransaction.commit();
            }
        });
        rel_back= (RelativeLayout) findViewById(R.id.rel_back);

        rel_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
</code></pre>

<p>fragment bird xml</p>

<pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"&gt;
&lt;ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/lv_bird"/&gt;
    &lt;/LinearLayout&gt;
</code></pre>

<p>Fragment java code</p>

<pre><code>public class FragmentRouteBirds extends Fragment {
AppSharedPreferences appSharedPreferences;
String REGISTER_URL="";
ListView lv_birds;
private ArrayList&lt;BirdsDataBean&gt; birdsUrlList;
boolean flag=false;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragments_birds, null);
    appSharedPreferences=AppSharedPreferences.getsharedprefInstance(getActivity());
     REGISTER_URL = "http://192.241.162.63/appvist/v1/routebird/"+appSharedPreferences.getRouteId();
    birdsUrlList = new ArrayList&lt;&gt;();
    lv_birds = (ListView) root.findViewById(R.id.lv_bird);
    LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) lv_birds.getLayoutParams();
    lp.height = LinearLayout.LayoutParams.MATCH_PARENT;
    lv_birds.setLayoutParams(lp);
    hitBirdsService();
    return root;
}
private void hitBirdsService() {
    class RegisterUser extends AsyncTask&lt;String, Void, String&gt; {
        private ProgressDialog mDialog;
        RequestClass ruc = new RequestClass();
        String response = "";

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            mDialog = new ProgressDialog(getActivity());
            mDialog.setMessage("Please Wait ...");
            mDialog.setCancelable(false);
            mDialog.show();
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            mDialog.dismiss();
            parseBirdResponse(response);
            //Toast.makeText(getActivity(), s, Toast.LENGTH_LONG).show();
        }

        @Override
        protected String doInBackground(String[] params) {

            response = RequestClass.GET(REGISTER_URL);

            return response;
        }
    }

    RegisterUser ru = new RegisterUser();
    ru.execute();
}
public void parseBirdResponse(String response) {
    //String descrip, String observaciones, String descrip_larga, String url_video, String url
    try {
        JSONObject jsonObject = new JSONObject(response);
        Boolean error = jsonObject.getBoolean("error");
        if (!error) {
            JSONArray jsonArray = jsonObject.getJSONArray("birds");
            for (int i = 0; i &lt; jsonArray.length(); i++) {
                JSONObject jsonBirds = jsonArray.getJSONObject(i);
                int idave=jsonBirds.getInt("idave");
                String descrip = jsonBirds.getString("descrip");
                String observaciones = jsonBirds.getString("observaciones");
                String descrip_larga = jsonBirds.getString("descrip_larga");
                String url_video = jsonBirds.getString("url_video");
                String url = jsonBirds.getString("url");
                String nombre_cientifico = jsonBirds.getString("nombre_cientifico");
                int flag=jsonBirds.getInt("flag");
                birdsUrlList.add(new BirdsDataBean(flag,idave,descrip, observaciones, descrip_larga, url_video, url, nombre_cientifico));

            }
            ScheduleTaskAdapter scheduleTaskAdapter = new ScheduleTaskAdapter(getActivity(), birdsUrlList);
            lv_birds.setAdapter(scheduleTaskAdapter);
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) lv_birds.getLayoutParams();
            lp.height = 800;
            lv_birds.setLayoutParams(lp);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
public class ScheduleTaskAdapter extends BaseAdapter {
    Context context;
    LayoutInflater layoutInflater;
    // List&lt;InterestAndLanguageBean&gt; interestAndLanguageBeans=new ArrayList&lt;&gt;();
    List&lt;BirdsDataBean&gt; imageList = new ArrayList&lt;&gt;();

    public ScheduleTaskAdapter(Context context, List&lt;BirdsDataBean&gt; imagesList) {
        this.context = context;
        this.imageList = imagesList;
        layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

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

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

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

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.routes_bird_row, parent, false);
            holder.iv_birds = (ImageView) convertView.findViewById(R.id.iv_route_bird);
            holder.frameLayout = (FrameLayout) convertView.findViewById(R.id.frame_route_bird);
            holder.linearLayout = (LinearLayout) convertView.findViewById(R.id.route_bird_detail_view);
            holder.imageView = (ImageView) convertView.findViewById(R.id.iv_hide);
            holder.iv_video = (ImageView) convertView.findViewById(R.id.iv_seen);
            holder.iv_sound = (ImageView) convertView.findViewById(R.id.iv_video);
            holder.tv_short_descript = (TextView) convertView.findViewById(R.id.tv_bird_name);
            holder.tv_category = (TextView) convertView.findViewById(R.id.tv_scientific_name);
            holder.tv_long_description = (TextView) convertView.findViewById(R.id.tv_description);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Uri myUri = Uri.parse(birdsUrlList.get(position).getUrl());
        Glide.with(getActivity()).load(myUri).placeholder(R.drawable.birds).into(holder.iv_birds);
        holder.tv_short_descript.setText(birdsUrlList.get(position).getDescrip());
        holder.tv_long_description.setText(birdsUrlList.get(position).getDescrip_larga());
        holder.tv_category.setText(birdsUrlList.get(position).getNombre_cientifico());
        final ViewHolder finalHolder = holder;
        holder.frameLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finalHolder.linearLayout.setVisibility(View.VISIBLE);
                finalHolder.iv_sound.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        try {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(birdsUrlList.get(position).getUrl_video())));
                        } catch (ActivityNotFoundException e) {
                            e.printStackTrace();
                        }
                    }
                });
                finalHolder.iv_video.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //hitBirdSeenService(birdsUrlList.get(position).getIdave());
                       // finalHolder.iv_video.setImageResource(R.drawable.eye_selected);
                    }
                });
            }
        });
        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finalHolder.linearLayout.setVisibility(View.GONE);
            }
        });
        //Picasso.with(context).load(myUri).placeholder(R.drawable.image).into(holder.pic);
        //malevich.load(helperTaskBeanList.get(position).getImage()).into(holder.pic);
        return convertView;
    }

}
static class ViewHolder {
    ImageView iv_birds,imageView,iv_video,iv_sound;
    FrameLayout frameLayout;
    LinearLayout linearLayout;
    TextView tv_short_descript,tv_category,tv_long_description;
}
</code></pre>

<p>}</p>

<p>And row layout for adapter</p>

<pre><code>    &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"&gt;
    &lt;FrameLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:id="@+id/frame_route_bird"
        xmlns:android="http://schemas.android.com/apk/res/android"&gt;
        &lt;ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="fitXY"
            android:id="@+id/iv_route_bird"/&gt;
        &lt;LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_gravity="bottom"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="10dp" &gt;
            &lt;TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#ffffff"
                android:text="@string/name"
                android:textSize="24sp"
                android:textStyle="bold"
                android:id="@+id/tv_bird_name"/&gt;
            &lt;TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="15sp"
                android:textColor="#ffffff"
                android:text="@string/bird_sub_category"
                android:id="@+id/tv_scientific_name"/&gt;

        &lt;/LinearLayout&gt;
    &lt;/FrameLayout&gt;
    &lt;LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:visibility="gone"
        android:background="#ffffff"
        android:id="@+id/route_bird_detail_view"
        android:paddingBottom="120dp"&gt;
        &lt;TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/bird_hidden_text"
            android:textSize="20sp"
            android:padding="20dp"
            android:id="@+id/tv_description"/&gt;
        &lt;LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_gravity="center"&gt;
            &lt;ImageView
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:src="@drawable/eye110"
                android:id="@+id/iv_seen"/&gt;
            &lt;ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/right"
                android:layout_marginTop="25dp"
                android:layout_marginLeft="15dp"
                android:id="@+id/iv_arrow"/&gt;
            &lt;ImageView
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:src="@drawable/ear"
                android:layout_marginLeft="15dp"
                android:id="@+id/iv_video"/&gt;
        &lt;/LinearLayout&gt;
        &lt;ImageView
            android:layout_width="match_parent"
            android:layout_height="20dp"
            android:background="#D6D6D6"
            android:layout_marginTop="20dp"
            android:src="@drawable/up"
            android:layout_gravity="center"
            android:id="@+id/iv_hide"/&gt;
    &lt;/LinearLayout&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p>Here are the screenshots of the problem<a href="https://i.stack.imgur.com/vC3m1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vC3m1.png" alt="This is the screen when fragment opens"></a></p>

<p><a href="https://i.stack.imgur.com/ipgC7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ipgC7.png" alt="This is when I make hidden view visible"></a></p>

<p>Comparing both images you can see that the hidden view appears in the space of the single row item and is scroll able completely in that space.</p>