RecyclerView と GridLayoutManager があります。列の幅は同じですが、80dp
幅のある最初の列が必要です。これは可能ですか?
例: RecyclerView 幅 5 列
final columnsCount = 5;
recyclerView.width = 500dp
column0.width = 80dp
column 1-2-3-4 width = (recyclerview.width - column0.width) / columnsCount
何かアドバイス?
編集:コード
public class TestRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int VIEW_TYPE_START = 0;
private static final int VIEW_TYPE_PROGRESS_ITEM = 1;
private LayoutInflater inflater;
public TestRecyclerViewAdapter(Context context) {
this.inflater = LayoutInflater.from(context);
}
@Override
public int getItemViewType(int position) {
if (position == 0) {
return VIEW_TYPE_START;
} else {
return VIEW_TYPE_PROGRESS_ITEM;
}
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
final View view;
switch (viewType) {
case VIEW_TYPE_START:
view = this.inflater.inflate(R.layout.view_item_small, parent, false);
return new TestViewHolder(view);
case VIEW_TYPE_PROGRESS_ITEM:
view = this.inflater.inflate(R.layout.view_item, parent, false);
return new TestViewHolder(view);
}
return null;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
}
@Override
public int getItemCount() {
return 5;
}
}
view_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0000FF"
android:orientation="vertical">
view_item_small.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="80dp"
android:layout_height="match_parent"
android:background="#FF0000"
android:orientation="vertical">
使用法:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
recyclerView.setAdapter(new TestRecyclerViewAdapter(this));
recyclerView.setLayoutManager(new GridLayoutManager(this, 5));
}