I have recyclerview to show my order items but it has design issue and after 3 days changing it I have no other solution for it!
screenshot
Issues
- Recyclerview is not covering page full height
- Items have space same as recyclerview height (it shows 1 item per page!)
Code
fragment_order.xml
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/orderItem" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".main.OrdersFragment"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/orders_list" android:layout_width="match_parent" android:layout_height="match_parent" /> </FrameLayout>
order_items.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content"> <androidx.cardview.widget.CardView android:id="@+id/cardView2" android:layout_width="match_parent" android:layout_height="70dp" android:layout_marginBottom="5dp" app:cardElevation="2dp" android:layout_margin="5dp"> <FrameLayout android:background="@color/orders" android:layout_width="4dp" android:layout_height="match_parent"/> <TextView android:id="@+id/order_Iid" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="10dp" android:gravity="start|top" android:text="@string/order_ID" android:textSize="12sp" android:textStyle="bold" /> <TextView android:id="@+id/order_status_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|start" android:layout_marginStart="10dp" android:layout_marginTop="35dp" android:text="@string/order_status" android:textColor="#5CDCBD" android:textSize="18sp" android:textStyle="bold" /> <TextView android:id="@+id/order_price_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|end" android:layout_marginEnd="10dp" android:text="@string/price" android:textSize="12sp" android:textStyle="bold" /> </androidx.cardview.widget.CardView> </LinearLayout>
OrdersFragment.kt
class OrdersFragment : Fragment() { lateinit var sesssion: SessionManager lateinit var laundriesRecycler: RecyclerView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { // Inflate the layout for this fragment val root = inflater.inflate(R.layout.fragment_orders, container, false) sesssion = SessionManager(context) laundriesRecycler = root.findViewById(R.id.orders_list) getOrders() return root } private fun getOrders() { var session = SessionManager(context) session.checkLogin() var user = session.getUserDetails() var token: String? = user.get(SessionManager.KEY_ACCESS_TOKEN) val tokenFull = "Bearer $token" val queue = Volley.newRequestQueue(context) val url = "https://example.com/api/orders" val stringReq : StringRequest = object : StringRequest( Method.GET, url, Response.Listener { response -> val list = Gson().fromJson(response, OrderArr::class.java) laundriesRecycler.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) laundriesRecycler.adapter = OrdersAdapter(context, list) }, Response.ErrorListener { Toast.makeText(context, R.string.errorMessage, Toast.LENGTH_LONG) .show() } ){ override fun getHeaders(): Map<String, String> { val headers = HashMap<String, String>() headers["Content-Type"] = "application/json" headers["Authorization"] = tokenFull return headers } } queue.add(stringReq) } }
Any idea?
https://stackoverflow.com/questions/66979423/recyclerview-design-issue April 07, 2021 at 12:07PM
没有评论:
发表评论