我一直在使用回收器视图,但不知道为什么在每个分区后都有黑线,尽管我没有任何代码来提升黑线。如果我没有使用任何volley库或picasso库,或者当我使用自己的数组列表时,它在没有任何分隔线的情况下工作得很好。这是XML代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llcontent"
android:layout_width="match_parent"
android:layout_height="140dp"
android:orientation="horizontal"
android:background="@color/white"
android:weightSum="6">
<!--The weight sum property is used to divide the layout into
different parts and then giving each layout a particular weight
gives it that amount of space on the screen-->
<!--Since each parent layout will have a specific weight, we need
not give any width to those layout-->
<ImageView
android:layout_weight="1.5"
android:id="@+id/imgBookImage"
android:layout_width="0dp"
android:layout_height="110dp"
android:src="@mipmap/ic_launcher"
android:scaleType="centerCrop"
android:padding="5dp"/>
<RelativeLayout
android:layout_weight="3.3"
android:layout_width="0dp"
android:layout_height="match_parent">
<TextView
android:id="@+id/txtBookName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name of the book"
android:padding="8dp"
android:textSize="18sp"
android:textColor="#000000"/>
<TextView
android:id="@+id/txtBookAuthor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtBookName"
android:padding="8dp"
android:text="Name of the Author"
android:textSize="15sp" />
<TextView
android:id="@+id/txtBookPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtBookAuthor"
android:layout_alignParentBottom="true"
android:padding="8dp"
android:text="Rs. 299"
android:textColor="#357a38"
android:textSize="15sp"
android:textStyle="bold" />
</RelativeLayout>
<!--Many times we see that texts have an image along with them to
their right or left. This is added with the help of the
drawableLeft (or drawableRight and so on) attribute-->
<TextView
android:id="@+id/txtBookRating"
android:layout_weight="1.2"
android:layout_width="0dp"
android:padding="4dp"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_ratings"
android:textColor="#ffca28"
android:text="4.5"
android:drawablePadding="4dp"
android:textSize="15sp"
android:textStyle="bold">
</TextView>
</LinearLayout>
这与Kotlin的代码相同:
package com.example.new_app.fragment
import android.app.Activity
import android.app.AlertDialog
import android.app.Dialog
import android.content.ContentValues.TAG
import android.content.Context
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.android.volley.Request
import com.android.volley.Response
import com.android.volley.toolbox.JsonObjectRequest
import com.android.volley.toolbox.Volley
import com.example.new_app.R
import com.example.new_app.adapter.Dashboard_Recycler_Adapter
import com.example.new_app.model.book
import isOnline
import java.util.stream.DoubleStream.builder
import java.util.stream.Stream.builder
import android.content.Intent
import android.provider.Settings
import androidx.core.app.ActivityCompat
import android.R.string.no
class dashboard_fragment : Fragment() {
lateinit var recyclerView: RecyclerView
lateinit var layoutManager: RecyclerView.LayoutManager
lateinit var adapter: Dashboard_Recycler_Adapter
var bookInfoList: ArrayList<book> = ArrayList()
val TAGG = "onCreateView"
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// val bookInfoList = arrayListOf<book>(
// book("1", "yname", "hfer", "200", "5", R.drawable.anna_kare)
// )
val view = inflater.inflate(R.layout.fragment_dashboard_fragment, container, false)
recyclerView = view.findViewById(R.id.rvdashboard)
layoutManager = LinearLayoutManager(activity)
adapter = Dashboard_Recycler_Adapter(activity as Context, bookInfoList)
recyclerView.adapter = adapter
recyclerView.layoutManager = layoutManager
val a = ((isOnline(activity as Context))).toString()
if(!isOnline(activity as Context)) {
val dialog = AlertDialog.Builder(activity as Context)
dialog.setTitle("Error")
dialog.setMessage("Network is not working")
dialog.setPositiveButton("Open settings"){
text, listener->
val intent = Intent(Settings.ACTION_WIRELESS_SETTINGS)
startActivity(intent)
}
dialog.setNegativeButton("Cancel"){
text, listener->
ActivityCompat.finishAffinity(activity as Activity)
}
dialog.create()
dialog.show()
return view
}
val queue = Volley.newRequestQueue(activity as Context)
val url = "http://13.235.250.119/v1/book/fetch_books/"
val jsonObjectRequest = object: JsonObjectRequest(Request.Method.GET,
url, null,
Response.Listener {
val success = it.getBoolean("success")
if(success)
{
val data = it.getJSONArray("data")
for(i in 0 until data.length())
{
val bookjsonobj = data.getJSONObject(i)
val booklist = book(
bookjsonobj.getString("book_id"),
bookjsonobj.getString("name"),
bookjsonobj.getString("author"),
bookjsonobj.getString("rating"),
bookjsonobj.getString("price"),
bookjsonobj.getString("image")
)
bookInfoList.add(booklist)
layoutManager = LinearLayoutManager(activity)
adapter = Dashboard_Recycler_Adapter(activity as Context, bookInfoList)
recyclerView.adapter = adapter
recyclerView.layoutManager = layoutManager
recyclerView.addItemDecoration(
DividerItemDecoration(
recyclerView.context,
(layoutManager as LinearLayoutManager).orientation
)
)
}
}
}, Response.ErrorListener {
print("Not proceccess")
})
{
override fun getHeaders(): MutableMap<String, String> {
val headers = hashMapOf<String, String>()
headers["Content-type"] = "application/json"
headers["token"] = ""
return headers
}
}
queue.add(jsonObjectRequest)
return view
}
}
1条答案
按热度按时间kr98yfug1#
在代码回收器视图绑定下面的代码块中添加分隔符删除此代码块。