I have a
1. Framelayout(frame1) in which I am inflating a RecyclerView layout with weight 0.5
2. Framelayout(frame2) with visibility gone and weight 0.5
My Recyclerview is occupying only half the width though frame2 is gone. If I use listview instead of RecyclerView, I dont have this issue. Can anyone suggest how to make Recyclerview occupy whole width ?
EDIT: If I scroll the recyclerview , it is taking up the whole width as expected.
Adapter
@Override
public ListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item, parent, false);
ListViewHolder tvh = new ListViewHolder (v);
return tvh;
}
main_layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<FrameLayout
android:id="@+id/frame1"
android:layout_width="0dp" // If I put match_parent here it works
android:layout_height="match_parent"
android:layout_weight="0.5"
/>
<FrameLayout
android:id="@+id/frame2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:visibility="gone" />
</LinearLayout>
frame1_layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
recycler_item
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_margin="5dp" >
<ImageView
android:id="@+id/imageIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:scaleType="centerCrop"
android:src="@drawable/ic_main" />
<TextView
android:id="@+id/textName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
android:layout_toRightOf="@+id/imageIcon"
android:textSize="14sp" />
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:text="Test"
android:layout_below="@+id/textName"
android:textSize="12sp" />
</RelativeLayout>