Я знаю, что, возможно, существует очень простое решение, но, судя по всему, я не могу его найти.Как изменить ширину элемента RecycleView?По какой-то причине он отображает первый элемент на всю ширину родительского элемента ... Он отображает много пустого пространства между каждым элементом.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_wrapper"
android:background="@color/colorPrimary"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:padding="20dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Categories"
android:textColor="#ffffff"
android:layout_marginBottom="10dp"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cats"
></android.support.v7.widget.RecyclerView>
</LinearLayout>
</LinearLayout>
CategoryAdapter:
public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.ViewHolder> {
private ArrayList<Category> categories;
public CategoryAdapter(ArrayList<Category> categories) {
this.categories = categories;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.single_cat, parent, false);
return new ViewHolder(v);
}
@Override public void onBindViewHolder(ViewHolder holder, int position) {
Category cat = this.categories.get(position);
holder.text.setText(cat.getText().toString());
}
@Override public int getItemCount() {
return categories.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView text;
public ViewHolder(View itemView) {
super(itemView);
text = (TextView) itemView.findViewById(R.id.cat_title);
}
}
}
single_cat.xml
<TextView
android:layout_width="100dp"
android:layout_height="40dp"
android:text="Cat"
android:background="@drawable/cat_single_shape"
android:padding="10dp"
android:gravity="center"
android:id="@+id/cat_title"
android:textSize="13sp"
android:fontFamily="@font/open_sans_bold"
android:textColor="@color/colorPrimary"/>