我使用的是recylcer视图,每一行都包含cardview,即使我的textview内容较少,我也需要显示cardview的全宽度。我尝试了很多方法,但都没用。
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/primaryDarkColor"
android:orientation="vertical">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardview"
android:background="#ffffff"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="8dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp"
android:orientation="horizontal">
<TextView
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="3dp"
android:text="content"
android:layout_weight="1"
android:textColor="#ff212121"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
即使我设置宽度来匹配父级,但没有用。
<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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#e5e5e5"
android:orientation="horizontal">
<android.support.v7.widget.RecyclerView
android:id="@+id/List"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</LinearLayout>
充气文档:
从指定的xml资源膨胀一个新的视图层次结构。如果出现错误,则引发IflateException。
要加载的XML布局资源(例如,r.layout.main_page)根视图的资源ID,以作为生成的层次结构的父视图(如果attachToRoot为true),或者简单地为返回的层次结构的根提供一组LayoutParams值的对象(如果attachToRoot为false)是否应该将膨胀的层次结构附加到根参数?如果为false,则root仅用于为XML中的root视图创建正确的LayoutParams子类。返回膨胀的层次结构的根视图。如果提供了root,并且attachToRoot为true,则为root;否则,它就是膨胀的XML文件的根。
LayoutInflater.from(parent.getContext())
.inflate(R.layout.card_listitem, parent, false);
ref:CardView layout_width=“match_parent”与父循环视图宽度不匹配
我已经用以下答案解决了我的问题
膨胀
的文档:
从指定的xml资源膨胀一个新的视图层次结构。如果出现错误,则引发IflateException。
LayoutInflater.from(parent.getContext())
.inflate(R.layout.card_listitem, parent, false);
这个答案帮助我解决了我的问题
ref:CardView layout_width=“match_parent”与父循环视图宽度不匹配
我正面临一个问题,我无法删除RecycerView中的一个项目。我试图在互联网上搜索,但无法看到任何解决方案,我遵循这篇文章Android Recycerview添加和删除项目,但我仍然无法删除下面选择的项目是我的适配器和碎片的代码 RecyclerViewAdapter.java
是否可以使用或者我必须构建自定义设计? 请帮忙。
我在你的论坛上潜伏了一段时间,他们在我遇到的各种问题上给了我巨大的帮助,所以谢谢!:d 我正试图创建我的第一个android应用程序,这是一个纸牌游戏,名为shithead,我和我的朋友们过去经常玩。 我觉得我必须非常接近,我只是错过了一些与android或android Studio工作的关键语法。 在我的卡片对象中,我构建了一个字符串idText,它与我保存在Android Studio中我的