我正在android v25中使用recyclerview和card view开发一个网格cardview,Android recycler view的面向行为有一条分隔线,充当两行之间的分隔符,如下图所示
我想删除这一行,我在此处附加我的布局 XMLS 和 java 代码
MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
categoriesAdapter = new RecyclerViewAdapter(getApplicationContext(),getAllItemList());
recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
// set a GridLayoutManager with default vertical orientation and 3 number of columns
GridLayoutManager gridLayoutManager = new GridLayoutManager(getApplicationContext(),3);
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(categoriesAdapter);
getAllItemList();
}
main_card_grid.xml
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_width="120dp"
android:layout_height="wrap_content"
card_view:cardUseCompatPadding="true"
card_view:cardCornerRadius="2dp"
android:layout_marginBottom="16dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/country_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/action_settings"
android:src="@drawable/eight"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/country_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="13sp"
android:text="@string/country_name"
android:textColor="@color/textColor"
android:gravity="center"
android:layout_below="@+id/country_photo"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:layout_alignParentBottom="true"
android:background="@color/white"/>
</RelativeLayout>
content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="groups.wtz.bluewine.com.miyo.MainActivity"
tools:showIn="@layout/app_bar_main">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
xml 的哪一部分使此下划线,我可以更新它
最佳答案
下线制造麻烦。因为您正在为您的元素添加装饰。这将为您的 View 添加分隔线。只需注释掉下面这一行即可。
recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
你能提供你的DividerItemDecoration.java类吗?
关于java - 如何以编程方式或使用 xml 属性删除回收器分隔符/分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46844606/