I have designed a layout with map fragment and recyclerView.
Each recyclerView item is cardview (I have specified give the xml layout).
The problem is RecyclerView item doesn't fill screen width.
img here
I tried to change layout_width to fill_parent, match_parent ... but it can't help
Here is the layout for each item
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:id="#+id/cardView">
<LinearLayout
android:id="#+id/locationItemView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="120px"
android:layout_height="120px"
android:id="#+id/imgIcon"
android:background="#drawable/image_bg"
android:layout_margin="5dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true" />
<LinearLayout
android:id="#+id/layoutInfo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="#+id/txtName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Location Name"
android:textColor="#d5c645"
android:textStyle="bold"
android:textSize="20dp"
android:padding="3dp" />
<TextView
android:id="#+id/txtAddress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Location Address"
android:textSize="16dp"
android:padding="3dp" />
<TextView
android:id="#+id/txtDistance"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:text="Location Distance"
android:textSize="14dp"
android:textStyle="italic"
android:padding="2dp"
android:textAlignment="viewEnd" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
and the main_layout
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="0px" android:id="#+id/map" tools:context=".Main"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_weight=".6"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/locationList"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight=".4"
android:divider="#FEFFCC"
android:dividerHeight="1dp" />
</LinearLayout>
<ListView
android:id="#+id/navdrawer"
android:layout_width="250px"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="?attr/colorPrimaryDark"
android:choiceMode="singleChoice"
android:divider="#android:color/white"
android:dividerHeight="1dp"
android:drawSelectorOnTop="false"/>
</android.support.v4.widget.DrawerLayout>
Hope anyone can help me. I am stuck with it for 3 days.
Thank you.
====================================
Edit on 19/11/15
I don't thing the problem is my itemView layout because when I change it to GridLayout it still doesn't fill the width.
Here is my CustomAdapter for RecyclerView
public class LocationDetailsAdapter extends RecyclerView.Adapter<LocationDetailsViewHolder> {
Context _context;
ArrayList<LocationDetails> _data;
public LocationDetailsAdapter(Context _context, ArrayList<LocationDetails> _object) {
this._context = _context;
_data = _object;
}
#Override
public LocationDetailsViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View _v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_location,null );
LocationDetailsViewHolder _viewHolder = new LocationDetailsViewHolder(_v);
return _viewHolder;
}
#Override
public void onBindViewHolder(LocationDetailsViewHolder locationDetailsViewHolder, int i) {
LocationDetails _location = _data.get(i);
locationDetailsViewHolder._imgType.setImageResource(R.drawable.repair_img);
locationDetailsViewHolder._locationName.setText(_location.get_locationName());
locationDetailsViewHolder._locationAddress.setText(_location.get_locationAddress() + ", " + _location.get_district() + ", " + _location.get_province());
locationDetailsViewHolder._distance.setText(String.valueOf(_location.get_distance()) + " km");
locationDetailsViewHolder._locationName.setOnClickListener(clickListener);
locationDetailsViewHolder._imgType.setOnClickListener(clickListener);
locationDetailsViewHolder._locationAddress.setOnClickListener(clickListener);
locationDetailsViewHolder._locationName.setTag(locationDetailsViewHolder);
locationDetailsViewHolder._imgType.setTag(locationDetailsViewHolder);
locationDetailsViewHolder._locationAddress.setTag(locationDetailsViewHolder);
}
#Override
public int getItemCount() {
return (null != _data ? _data.size() : 0);
}
View.OnClickListener clickListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
LocationDetailsViewHolder _holder = (LocationDetailsViewHolder)v.getTag();
int _pos = _holder.getPosition();
int _id = _data.get(_pos).get_id();
Intent _intent = new Intent(CommonFields._context, ItemView.class);
_intent.putExtra("LocationID",_id);
_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
CommonFields._context.startActivity(_intent);
}
};
}
and here I get RecylerView in main
_locationView = (RecyclerView)findViewById(R.id.locationList);
_locationView.setLayoutManager(new LinearLayoutManager(this));
_adapter = new LocationDetailsAdapter(Main.this, CommonFields._locationData);
_locationView.setAdapter(_adapter);
When inflating a View from a LayoutInflater, you need to pass a parent parameter in order for layout_* attributes to be used. That's because these attributes need to create the correct LayoutParams class. That means that you can't use inflate(R.layout.*, null), but must instead pass a ViewGroup for the second parameter. In most cases, you also want to use the three-parameter version of the method and pass false as the third parameter. If this is omitted or true then the View is immediately added to the parent, which causes problems in places like onCreateViewHolder() because the framework is designed to perform this operation later instead. For more details, see this answer.
In your case, you have the line
View _v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_location,null );
You should change it to
View _v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_location, viewGroup, false );
You should create View like this
#Override
public CardViewDataAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
// create a new view
View itemLayoutView = LayoutInflater.from(viewGroup.getContext()).inflate(
R.layout.card_view, viewGroup, false);
// create ViewHolder
ViewHolder viewHolder = new ViewHolder(itemLayoutView);
return viewHolder;
}
Maybe my answer has a different approach, but it works to occupy the entire width of the screen and not break the elements when passing through the recycling view.
Adapter adapterBalanceInquiry = new Adapter(getActivity(), list);
recyclerView.setHasFixedSize(true);
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setAdapter(adapterBalanceInquiry);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), RecyclerView.HORIZONTAL, false));
recyclerView.post(new Runnable() {
#Override
public void run() {
try {
int dx = (recyclerView.getWidth() - recyclerView.getChildAt(0).getWidth());
recyclerView.scrollBy(-dx, 0);
LinearSnapHelper snapHelper = new LinearSnapHelper();
recyclerView.setOnFlingListener(null);
snapHelper.attachToRecyclerView(recyclerView);
}catch (Exception e){
e.printStackTrace();
}
}
});
Related
I have three horizontal scrolling recycler views that are too large vertically for the app screen. To solve this, I nested them inside a NestedScrollView however the vertical scroll doesn't go all the way to the bottom of the last recycler view.
This is as far as the view will scroll:
Here's my config:
Container View:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="#+id/recyclerTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/recycler_with_filters"/>
<include
android:id="#+id/recyclerMiddle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/recycler_with_filters"/>
<include
android:id="#+id/recyclerBottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/recycler_with_filters"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
Included layout:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="Test!"
android:textColor="#color/colorPrimaryDark"
android:textSize="24sp"
app:fontFamily="#font/didot"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="#+id/filters"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#id/header">
<Button
android:id="#+id/filter1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/btn_filter_inactive"
android:textColor="#color/colorPrimaryDark"
android:text="filter1" />
<Button
android:id="#+id/filter2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/btn_filter_inactive"
android:textColor="#color/colorPrimaryDark"
android:text="filter2" />
<Button
android:id="#+id/filter3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/btn_filter_inactive"
android:textColor="#color/colorPrimaryDark"
android:text="filter3" />
<Button
android:id="#+id/filter4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/btn_filter_inactive"
android:textColor="#color/colorPrimaryDark"
android:text="filter4" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:scrollbars="vertical"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#id/filters" />
</androidx.constraintlayout.widget.ConstraintLayout>
Controller:
public class TestRecyclerFragment extends Fragment {
public static TestRecyclerFragment newInstance() {
return new TestRecyclerFragment();
}
private RecyclerView mRecyclerViewTop;
private RecyclerView mRecyclerViewMiddle;
private RecyclerView mRecyclerViewBottom;
private RecyclerView.Adapter mAdapterTop;
private RecyclerView.Adapter mAdapterMiddle;
private RecyclerView.Adapter mAdapterBottom;
private Business[] mBusinesses = {new Business("The Tavern", 0), new Business("The Tavern1", 0), new Business("The Tavern2", 0), new Business("The Tavern3", 0), new Business("The Tavern4", 0), new Business("The Tavern5", 0), new Business("The Tavern6", 1), new Business("The Tavern7", 1), new Business("The Tavern8", 1), new Business("The Tavern9", 1), new Business("The Tavern10", 1), new Business("The Tavern11", 1)};
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_test_recycler, container, false);
View recycleWithFilterTop = v.findViewById(R.id.recyclerTop);
mRecyclerViewTop = recycleWithFilterTop.findViewById(R.id.recycler_view);
View recycleWithFilterMiddle = v.findViewById(R.id.recyclerMiddle);
mRecyclerViewMiddle = recycleWithFilterMiddle.findViewById(R.id.recycler_view);
View recycleWithFilterBottom = v.findViewById(R.id.recyclerBottom);
mRecyclerViewBottom = recycleWithFilterBottom.findViewById(R.id.recycler_view);
mRecyclerViewTop.setHasFixedSize(true);
mRecyclerViewMiddle.setHasFixedSize(true);
mRecyclerViewBottom.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManagerTop = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
mRecyclerViewTop.setLayoutManager(layoutManagerTop);
RecyclerView.LayoutManager layoutManagerMiddle = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
mRecyclerViewMiddle.setLayoutManager(layoutManagerMiddle);
RecyclerView.LayoutManager layoutManagerBottom = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
mRecyclerViewBottom.setLayoutManager(layoutManagerBottom);
mAdapterTop = new TestRecyclerFragment.TestAdapter(mBusinesses);
mRecyclerViewTop.setAdapter(mAdapterTop);
mAdapterMiddle = new TestRecyclerFragment.TestAdapter(mBusinesses);
mRecyclerViewMiddle.setAdapter(mAdapterMiddle);
mAdapterBottom = new TestRecyclerFragment.TestAdapter(mBusinesses);
mRecyclerViewBottom.setAdapter(mAdapterBottom);
return v;
}
public class TestAdapter extends RecyclerView.Adapter<TestAdapter.MyViewHolder> {
private Business[] businesses;
public class MyViewHolder extends RecyclerView.ViewHolder {
private TextView mBusinessName;
public MyViewHolder(View v) {
super(v);
mBusinessName = itemView.findViewById(R.id.businessName);
}
}
public TestAdapter(Business[] myDataset) {
mBusinesses = myDataset;
}
#Override
public TestAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.view_holder_businesses, parent, false);
MyViewHolder vh = new MyViewHolder(v);
return vh;
}
#Override
public void onBindViewHolder(MyViewHolder holder, int position) {
holder.mBusinessName.setText(mBusinesses[position].getName());
}
// Return the size of your dataset (invoked by the layout manager)
#Override
public int getItemCount() {
return mBusinesses.length;
}
#Override
public int getItemViewType(int position) {
return mBusinesses[position].getViewType();
}
}
}
*Edit: I think the issue has to do with the scroll not knowing how large the view is going to be at the time it draws the view. I've tried hard-coding the heights in the include like this:
<include
android:id="#+id/recyclerTop"
android:layout_width="match_parent"
android:layout_height="400dp"
layout="#layout/recycler_with_filters"/>
However that messes up the view.
*Edit2: I've tried many of the solutions advocated in other questions on this topic including setting setting nestedScrollingEnabling to false. These solutions don't work in my instance. I'm not sure if it's a difference in my configuration or that I'm using a newer version of the NestedScrollView api.
Adding static height is not a proper solution considering different screen resolutions in the market. If you want to have multiple Recyclerviews scrolls as a whole inside NestedScrollView you should consider adding android:nestedScrollingEnabled="false" to Recyclerview:
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/margin_activity_horizontal">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="LinearLayoutManager"
android:nestedScrollingEnabled="false"/>
<android.support.v7.widget.RecyclerView
android:layout_below="#+id/recycler_view_departments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="LinearLayoutManager"
android:nestedScrollingEnabled="false"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
I've tested your code, it's working perfectly my side, Just I've added below 3 lines of code in TestRecyclerFragment onCreateView method
mRecyclerViewTop.setNestedScrollingEnabled(false);
mRecyclerViewMiddle.setNestedScrollingEnabled(false);
mRecyclerViewBottom.setNestedScrollingEnabled(false);
You can see working demo https://www.dropbox.com/s/zmfmcdjw58cto4q/device-2019-09-05-115921.mp4?dl=0
I was able to get the scroll view to scroll to the bottom by adding a dynamic height to the layout params of my bottom recycler view:
RecyclerView.LayoutManager layoutManagerBottom = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
mRecyclerViewBottom.setLayoutManager(layoutManagerBottom);
final float scale = getContext().getResources().getDisplayMetrics().density;
int pixels = (int) (550 * scale + 0.5f);
mRecyclerViewBottom.getLayoutParams().height = pixels;
I have designed a layout with map fragment and recyclerView.
Each recyclerView item is cardview (I have specified give the xml layout).
The problem is RecyclerView item doesn't fill screen width.
img here
I tried to change layout_width to fill_parent, match_parent ... but it can't help
Here is the layout for each item
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:id="#+id/cardView">
<LinearLayout
android:id="#+id/locationItemView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="120px"
android:layout_height="120px"
android:id="#+id/imgIcon"
android:background="#drawable/image_bg"
android:layout_margin="5dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true" />
<LinearLayout
android:id="#+id/layoutInfo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="#+id/txtName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Location Name"
android:textColor="#d5c645"
android:textStyle="bold"
android:textSize="20dp"
android:padding="3dp" />
<TextView
android:id="#+id/txtAddress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Location Address"
android:textSize="16dp"
android:padding="3dp" />
<TextView
android:id="#+id/txtDistance"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:text="Location Distance"
android:textSize="14dp"
android:textStyle="italic"
android:padding="2dp"
android:textAlignment="viewEnd" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
and the main_layout
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="0px" android:id="#+id/map" tools:context=".Main"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_weight=".6"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/locationList"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight=".4"
android:divider="#FEFFCC"
android:dividerHeight="1dp" />
</LinearLayout>
<ListView
android:id="#+id/navdrawer"
android:layout_width="250px"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="?attr/colorPrimaryDark"
android:choiceMode="singleChoice"
android:divider="#android:color/white"
android:dividerHeight="1dp"
android:drawSelectorOnTop="false"/>
</android.support.v4.widget.DrawerLayout>
Hope anyone can help me. I am stuck with it for 3 days.
Thank you.
====================================
Edit on 19/11/15
I don't thing the problem is my itemView layout because when I change it to GridLayout it still doesn't fill the width.
Here is my CustomAdapter for RecyclerView
public class LocationDetailsAdapter extends RecyclerView.Adapter<LocationDetailsViewHolder> {
Context _context;
ArrayList<LocationDetails> _data;
public LocationDetailsAdapter(Context _context, ArrayList<LocationDetails> _object) {
this._context = _context;
_data = _object;
}
#Override
public LocationDetailsViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View _v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_location,null );
LocationDetailsViewHolder _viewHolder = new LocationDetailsViewHolder(_v);
return _viewHolder;
}
#Override
public void onBindViewHolder(LocationDetailsViewHolder locationDetailsViewHolder, int i) {
LocationDetails _location = _data.get(i);
locationDetailsViewHolder._imgType.setImageResource(R.drawable.repair_img);
locationDetailsViewHolder._locationName.setText(_location.get_locationName());
locationDetailsViewHolder._locationAddress.setText(_location.get_locationAddress() + ", " + _location.get_district() + ", " + _location.get_province());
locationDetailsViewHolder._distance.setText(String.valueOf(_location.get_distance()) + " km");
locationDetailsViewHolder._locationName.setOnClickListener(clickListener);
locationDetailsViewHolder._imgType.setOnClickListener(clickListener);
locationDetailsViewHolder._locationAddress.setOnClickListener(clickListener);
locationDetailsViewHolder._locationName.setTag(locationDetailsViewHolder);
locationDetailsViewHolder._imgType.setTag(locationDetailsViewHolder);
locationDetailsViewHolder._locationAddress.setTag(locationDetailsViewHolder);
}
#Override
public int getItemCount() {
return (null != _data ? _data.size() : 0);
}
View.OnClickListener clickListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
LocationDetailsViewHolder _holder = (LocationDetailsViewHolder)v.getTag();
int _pos = _holder.getPosition();
int _id = _data.get(_pos).get_id();
Intent _intent = new Intent(CommonFields._context, ItemView.class);
_intent.putExtra("LocationID",_id);
_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
CommonFields._context.startActivity(_intent);
}
};
}
and here I get RecylerView in main
_locationView = (RecyclerView)findViewById(R.id.locationList);
_locationView.setLayoutManager(new LinearLayoutManager(this));
_adapter = new LocationDetailsAdapter(Main.this, CommonFields._locationData);
_locationView.setAdapter(_adapter);
When inflating a View from a LayoutInflater, you need to pass a parent parameter in order for layout_* attributes to be used. That's because these attributes need to create the correct LayoutParams class. That means that you can't use inflate(R.layout.*, null), but must instead pass a ViewGroup for the second parameter. In most cases, you also want to use the three-parameter version of the method and pass false as the third parameter. If this is omitted or true then the View is immediately added to the parent, which causes problems in places like onCreateViewHolder() because the framework is designed to perform this operation later instead. For more details, see this answer.
In your case, you have the line
View _v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_location,null );
You should change it to
View _v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_location, viewGroup, false );
You should create View like this
#Override
public CardViewDataAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
// create a new view
View itemLayoutView = LayoutInflater.from(viewGroup.getContext()).inflate(
R.layout.card_view, viewGroup, false);
// create ViewHolder
ViewHolder viewHolder = new ViewHolder(itemLayoutView);
return viewHolder;
}
Maybe my answer has a different approach, but it works to occupy the entire width of the screen and not break the elements when passing through the recycling view.
Adapter adapterBalanceInquiry = new Adapter(getActivity(), list);
recyclerView.setHasFixedSize(true);
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setAdapter(adapterBalanceInquiry);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), RecyclerView.HORIZONTAL, false));
recyclerView.post(new Runnable() {
#Override
public void run() {
try {
int dx = (recyclerView.getWidth() - recyclerView.getChildAt(0).getWidth());
recyclerView.scrollBy(-dx, 0);
LinearSnapHelper snapHelper = new LinearSnapHelper();
recyclerView.setOnFlingListener(null);
snapHelper.attachToRecyclerView(recyclerView);
}catch (Exception e){
e.printStackTrace();
}
}
});
I want to add horizontal recyclerview at the bottom of fragment. I followed the tutorial and successfully implemented horizontal recyclerview and cardview but after trying all possible answers,horizontal scrolling is not working.
Here is my code :-
XML :-
<RelativeLayout tools:context="com.AlfaCab.Menuactivtiy"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:layout_marginTop="56dp"
android:id="#+id/Mainlayout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#color/BgColor"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:background="#drawable/offer_white_box">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Offers"
android:gravity="center"
android:textSize="18sp"
android:textColor="#color/BlackTextColor"
android:textStyle="bold"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView_offer"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
android:scrollbars="none"/>
<!-- android:orientation="horizontal"
android:scrollbars="horizontal"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
/> -->
</LinearLayout>
</RelativeLayout>
Here is my offer_cardview.xml / custom layout for recyclerview :-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<!-- <!–Offer Start–>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/offer_white_box">
-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!--Offer Coupon-->
<LinearLayout
android:layout_width="140dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/round_box"
>
<LinearLayout
android:id="#+id/ll_offer_bg"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal"
android:background="#drawable/offer_red_box"
android:layout_marginBottom="3dp">
<TextView
android:id="#+id/tv_offer_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Get 30% Cashback"
android:textSize="12sp"
android:textColor="#color/WhiteTextColor"
android:textStyle="bold"
android:layout_gravity="center_vertical"
android:gravity="center"/>
</LinearLayout>
<TextView
android:id="#+id/tv_offer_disc"
android:layout_width="match_parent"
android:layout_height="80dp"
android:text="upto Rs. 300 cashback on Outstation"
android:textSize="10sp"
android:textColor="#color/BlackTextColor"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"/>
</LinearLayout>
<!--Offer Coupon Ends-->
</LinearLayout>
<!--</LinearLayout>-->
<!--Offer Ends-->
</android.support.v7.widget.CardView>
</LinearLayout>
HomeFragment.java :-
//a list to store all the products
List<Offer_Data> offerList;
//the recyclerview
RecyclerView recyclerView;
String appOfferId,appOfferTitle,appOfferDes,status;
In onCreate :-
//getting the recyclerview from xml
recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView_offer);
After successfully adding data to offerList :-
//creating recyclerview adapter
Offer_Adapter adapter = new Offer_Adapter(getActivity(), offerList);
//adapter.notifyDataSetChanged();
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
recyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();// Notify the adapter
Offer_Adapter.java :- (Recyclervire adapter)
public class Offer_Adapter extends RecyclerView.Adapter<Offer_Adapter.ProductViewHolder> {
int[] myImageList;
//this context we will use to inflate the layout
private Context mCtx;
//we are storing all the products in a list
private List<Offer_Data> offerList;
//getting the context and product list with constructor
public Offer_Adapter(Context mCtx, List<Offer_Data> offerList) {
this.mCtx = mCtx;
this.offerList = offerList;
this.myImageList = new int[]{R.drawable.offer_red_box, R.drawable.offer_megento_box, R.drawable.offer_yellow_box};
}
#Override
public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//inflating and returning our view holder
LayoutInflater inflater = LayoutInflater.from(mCtx);
View view = inflater.inflate(R.layout.offer_cardview, null);
return new ProductViewHolder(view);
}
#Override
public void onBindViewHolder(ProductViewHolder holder, int position) {
//getting the product of the specified position
Offer_Data product = offerList.get(position);
//binding the data with the viewholder views
holder.tv_offer_title.setText(product.getOffer_title());
holder.tv_offer_disc.setText(product.getOffer_disc());
int random_box = getRandom(myImageList);
holder.ll_offer_bg.setBackgroundResource(random_box);
}
public static int getRandom(int[] array) {
int rnd = new Random().nextInt(array.length);
return array[rnd];
}
#Override
public int getItemCount() {
return offerList.size();
}
class ProductViewHolder extends RecyclerView.ViewHolder {
TextView tv_offer_title, tv_offer_disc;
LinearLayout ll_offer_bg;
public ProductViewHolder(View itemView) {
super(itemView);
tv_offer_title = (TextView) itemView.findViewById(R.id.tv_offer_title);
tv_offer_disc = (TextView) itemView.findViewById(R.id.tv_offer_disc);
ll_offer_bg = (LinearLayout)itemView.findViewById(R.id.ll_offer_bg);
}
}
}
Please, help me to make it scroll horizontally.
LinearLayoutManager linearLayoutManager
= new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(linearLayoutManager);
Found the Problem
Change this line
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
to
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
Problem is that , you are passing wrong context to recycler view manager
Should use getActivity() not getContext()
ALso no need to add this line in xml
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
I will fill view by adapter and when iam fill data to RV then can not scroll.
This is my RC:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/trip_ticket_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/trip_ticket_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.v4.widget.SwipeRefreshLayout>
RC is fill by this view:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/TripMyTicketScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical">
<Button
android:id="#+id/my_ticket_port_and_directions"
android:layout_width="match_parent"
android:layout_height="#dimen/grid_14"
android:layout_marginEnd="#dimen/grid_2"
android:layout_marginLeft="#dimen/grid_2"
android:layout_marginRight="#dimen/grid_2"
android:layout_marginStart="#dimen/grid_2"
android:layout_marginTop="#dimen/grid_1"
android:height="#dimen/grid_5"
android:background="#color/bg_on_board_button"
android:drawableEnd="#drawable/ic_keyboard_arrow_right"
android:drawableLeft="#drawable/ic_rudder_black_32dp"
android:drawablePadding="6dp"
android:drawableRight="#drawable/ic_keyboard_arrow_right"
android:drawableStart="#drawable/ic_rudder_black_32dp"
android:gravity="center|start"
android:padding="#dimen/grid_2"
android:text="#string/my_ticket_port_and_direction"
android:textColor="#color/text_color_my_trip_button"
android:textStyle="bold" />
<include layout="#layout/view_my_trip_time_schedule" />
<include layout="#layout/view_my_trip_passengers_and_cabins" />
<include layout="#layout/view_my_trip_booking_number" />
</LinearLayout>
There are some linear layouts with buttons and textview in <include layout=...
And when view across the screen size then normally start scroll but in this case not.
Adapter is empty for now because i have to solve this problem a them i will continue.
Can you help me?
Thank you.
Update
This is RC init in Fragment
private void initRecyclerView(){
mAdapter = new MyTicketAdapter(getContext());
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerRv.setLayoutManager(mLayoutManager);
mRecyclerRv.setAdapter(mAdapter);
}
Adapter does not fill any data for now. Here is adapter:
public class MyTicketAdapter extends RecyclerView.Adapter<MyTicketAdapter.MyViewHolder> {
private static final int BARCODE_IMAGE_WIDTH = 150;
private static final int BARCODE_IMAGE_HEIGHT = 40;
private Departure mDeparture;
private final Context mContext;
public class MyViewHolder extends RecyclerView.ViewHolder {
//
// #BindView(R.id.my_ticket_booking_number_barcode_ticket)
// ImageView mBarcodeImageView;
//
// #BindView(R.id.my_ticket_booking_number_barcode_booking_number)
// TextView mBookingNumberBelowBarcode;
//
public MyViewHolder(View view) {
super(view);
ButterKnife.bind(this, view);
}
}
/**
* Creates a new instance of this class.
*
* #param context need values from resource.
*/
public MyTicketAdapter(Context context) {
mContext = context;
}
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_item_trip_ticket, parent, false);
return new MyViewHolder(itemView);
}
#Override
public void onBindViewHolder(MyTicketAdapter.MyViewHolder holder, int position) {
if (mDeparture == null) {
return;
}
TravelMateLogs.MY_TICKET_ADAPTER.i("--------Departure: " + mDeparture.toString());
// generateBarcode(holder);
}
#Override
public int getItemCount() {
// There is only one item.
if(mDeparture == null){
return 0;
}else {
return 1;
}
}
/**
* Sets the data to be displayed in the list.
*
* #param departure The departure to be displayed in the view. Null will clear the list.
*/
void setData(#Nullable Departure departure) {
mDeparture = departure;
notifyDataSetChanged();
}
}
<android.support.v7.widget.RecyclerView
android:id="#+id/trip_ticket_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
If is wrap, recyclerview is not visible. Also please post recyclerview initialisation.
Solution:
I had to wrap all part to linearlayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/TripMyTicketScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/bg_trip_tab_view"
android:orientation="vertical"
android:paddingBottom="#dimen/grid_14">
<include layout="#layout/view_my_trip_time_schedule" />
<include layout="#layout/view_my_trip_passengers_and_cabins" />
<include layout="#layout/view_my_trip_booking_number" />
</LinearLayout>
</LinearLayout>
Now it is work ...
I am trying to incorporate 2 lists "sections" into a LinearLayout via height weights. The issue that I am having is that, though the container for the "section" is displayed with the proper height (where the background is sub_gray), and the adapter count is correct, the height of my actual list rows is 0 which makes my list appear invisible.
LIST ITEM
Below is the code that my list rows/items directly work with. To avoid the wall of code getting too long, I will include my code for one of the lists seeing as they are both behaving the same.
layout_quick_guide_checklist_item
<?xml version="1.0" encoding="utf-8"?>
<com.my_project.project.QuickGuideChecklistListItemView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:background="#color/sub_gray"
android:orientation="horizontal" >
<CheckBox
android:id="#+id/checkbox_checklist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_gravity="center"
android:checked="true"
android:clickable="false" />
<TextView
android:id="#+id/text_field"
style="#style/default_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="#string/height_wrap_string"/>
</com.my_project.project.QuickGuideChecklistListItemView>
QuickGuideChecklistListItemView
public class QuickGuideChecklistListItemView extends LinearLayout{
private TextView listText;
public QuickGuideChecklistListItemView(Context context) {
super(context);
}
public QuickGuideChecklistListItemView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public QuickGuideChecklistListItemView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
public static QuickGuideChecklistListItemView inflate(ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) parent.getContext().
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
QuickGuideChecklistListItemView itemView = (QuickGuideChecklistListItemView)
inflater.inflate(R.layout.layout_quick_guide_checklist_item, parent, false);
return itemView;
}
#Override
public void onFinishInflate(){
super.onFinishInflate();
listText = (TextView) findViewById(R.id.text_field);
}
public void setText(String text){
listText.setText(text);
}
}
COMPLETE LIST
Now I take the above code and use it within my activity to create a list (recall; there are actually two lists in my activity, constructed similarly, and both resulting in row heights of 0).
QuickGuideDetailActivity
public class QuickGuideDetailActivity extends NavigationDrawerActivity implements OnClickListener{
private final String TAG = getClass().getSimpleName();
private QuickGuideModel selectedQuickGuide;
private QuickGuideChecklistAdapter checklistAdapter;
private QuickGuideTipAdapter tipsAdapter;
private TextView quickGuidesTitle, quickGuidesDescription, inflaterButton;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
selectedQuickGuide = QuickGuidesActivity.selectedQuickGuide;
buildLists();
}
#Override
protected int getLayoutId(){
return R.layout.sub_activity_quick_guide;
}
public void checkAdapterSize(View v){
String checklistString = (checklistAdapter == null)? "null": "" + checklistAdapter.getCount();
String tipString = (tipsAdapter == null)? "null": "" + tipsAdapter.getCount();
Toast.makeText(this, checklistString + " : " + tipString,
Toast.LENGTH_SHORT).show();
}
private void buildLists(){
TextView checklistTitle = (TextView) findViewById(R.id.checklist_title_bar);
checklistTitle.setText(getResources().getString(R.string.title_checklist));
ArrayList<String> checklistStrings = new ArrayList<String>();
for(Object guide : selectedQuickGuide.checklist){
checklistStrings.add((String) guide.toString());
}
checklistAdapter = new QuickGuideChecklistAdapter(checklistStrings);
ListView checklist = (ListView) findViewById(R.id.checklist_list);
checklist.setAdapter(checklistAdapter);
Log.d(TAG, "List Size - Checklist = " + selectedQuickGuide.checklist.length);
TextView tipsTitle = (TextView) findViewById(R.id.tips_title_bar);
tipsTitle.setText(getResources().getString(R.string.title_tips));
tipsAdapter = new QuickGuideTipAdapter(selectedQuickGuide.topTips);
ListView tips = (ListView) findViewById(R.id.tips_list);
tips.setAdapter(tipsAdapter);
Log.d(TAG, "List Size - Tips = " + selectedQuickGuide.topTips.length);
}
}
sub_activity_quick_guide
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/nav_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
style="#style/default_container"
android:layout_margin="15dp"
android:orientation="vertical" >
<include
android:id="#+id/expandable_section"
layout="#layout/section_expandable_details" />
<LinearLayout
style="#style/default_container"
android:orientation="vertical"
android:weightSum="2">
<LinearLayout
android:id="#+id/checklist_section"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginBottom="8dp"
android:background="#color/sub_gray"
android:onClick="checkAdapterSize" >
<View
android:layout_width="1dp"
android:layout_height="15dp" />
<TextView
android:id="#+id/checklist_title_bar"
style="#style/default_label_text_view"
android:background="#color/random_blue"
android:text="#string/loading" />
<ListView
android:id="#+id/checklist_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#color/off_white"
android:dividerHeight="1dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/tips_list_section"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="7dp"
android:background="#color/sub_gray"
android:onClick="checkAdapterSize" >
<View
android:layout_width="1dp"
android:layout_height="15dp" />
<TextView
android:id="#+id/tips_title_bar"
style="#style/default_label_text_view"
android:background="#color/random_blue"
android:text="#string/loading" />
<ListView
android:id="#+id/tips_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#color/off_white"
android:dividerHeight="1dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="#+id/nav_drawer_list_view"
android:layout_width="#dimen/drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#android:color/white" />
</android.support.v4.widget.DrawerLayout>
QuickGuideChecklistAdapter
public class QuickGuideChecklistAdapter extends BaseAdapter{
private ArrayList<String> guides;
private List<Boolean> checklistItemTicked = new ArrayList<Boolean>();
public QuickGuideChecklistAdapter(ArrayList<String> guides){
this.guides = guides;
for(int i = 0; i < guides.size(); i++)
checklistItemTicked.add(false);
}
#Override
public int getCount() {
return guides.size();
}
#Override
public String getItem(int position) {
if(position < 0 || position >= guides.size())
throw new IndexOutOfBoundsException("Position is out of range of list with size " + guides.size());
return guides.get(position);
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
QuickGuideChecklistListItemView itemView = (QuickGuideChecklistListItemView)convertView;
if (null == itemView)
itemView = QuickGuideChecklistListItemView.inflate(parent);
itemView.setText(guides.get(position));
Log.d(getClass().getSimpleName(), "Setting text to " + guides.get(position) + " in position " + position);
return itemView;
}
}
Sorry for the wall of code, but I have tried adjusting everything and just can't seem to get anything to work. So just as a final bit:
The adapters are set, getCount() returns the valid count of items in the list and clicking on the layouts in order to call checkAdapterSize() also results in a Toast with the proper values.
The first view is "inflated" but results in a view height of 0.
The container layouts for my list "sections" (checklist_section in sub_activity_quick_guide for example) have a height which can be seen by the sub_gray background.
I have tried changing height attributes from match_parent to wrap_content and vice versa with no luck. I have tried explicitly declaring a minHeight for my list items and all that good stuff. I just can't seem to ever get a list row item to actually inflate.
Funny how I always manage to figure out an answer to my own questions right after I post a question on SO after days of trying :P
Anyway, the issue was in placing my ListViews inside of LinearLayouts with heights determined by weight. I removed the LinearLayout wrappers for my "sections" and applied the weights to my ListViews directly, voila... good to go.
New complete working Activity layout
sub_activity_quick_guide
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/nav_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
style="#style/default_container"
android:layout_margin="15dp"
android:orientation="vertical"
android:weightSum="2" >
<include
android:id="#+id/expandable_section"
layout="#layout/section_expandable_details" />
<View
android:layout_width="1dp"
android:layout_height="15dp" />
<TextView
android:id="#+id/checklist_title_bar"
style="#style/default_label_text_view"
android:background="#color/random_blue"
android:text="#string/loading" />
<ListView
android:id="#+id/checklist_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="#color/off_white"
android:dividerHeight="1dp" />
<View
android:layout_width="1dp"
android:layout_height="15dp" />
<TextView
android:id="#+id/tips_title_bar"
style="#style/default_label_text_view"
android:background="#color/random_blue"
android:text="#string/loading" />
<ListView
android:id="#+id/tips_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="#color/off_white"
android:dividerHeight="1dp" />
</LinearLayout>
<RelativeLayout
android:id="#+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="#+id/nav_drawer_list_view"
android:layout_width="#dimen/drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#android:color/white" />
</android.support.v4.widget.DrawerLayout>
Hope it helps someone in the future, didn't realize weights would mess with it like that but apparently ListViews don't like weighted containers.