Hello,
Welcome to our Microsoft Q&A platform!
To specify a dynamic size for the recyclerView, please set both the android:layout_width
of the recyclerView and the android:layout_width
of item's layout to wrap_content.
//main_layout.xaml
<LinearLayout ...
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/recyclerView1" />
</LinearLayout>
//item_ayout.xaml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!--the views-->
</LinearLayout>
The related code about populating data for the recyclerView.
public class TestActivity : Activity
{
RecyclerView recyclerView;
RecyclerView.LayoutManager mLayoutManager;
List<model> list;
CustomAdapter adapter;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.layout2);
recyclerView = FindViewById<RecyclerView>(Resource.Id.recyclerView1);
mLayoutManager = new GridLayoutManager(this, 3);
recyclerView.SetLayoutManager(mLayoutManager);
list = xxx;//add the data
adapter = new CustomAdapter(list, this);
recyclerView.SetAdapter(adapter);
}
}
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.