java - 如何在 RecyclerView 中设置 RelativeLayoutManager 而不是使用 LinearLayoutManager
问题描述
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:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:background="@color/colorAccent"
tools:context=".DebitedTab">
<android.support.v7.widget.CardView
android:layout_width="380dp"
android:layout_height="wrap_content"
android:id="@+id/debitedCV"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/debitLayout"
android:layout_margin="16dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="@string/GiverNames"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginRight="4dp"
android:id="@+id/Giver"
/>
<TextView
android:text=""
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/debtorNames"
android:layout_toRightOf="@+id/Giver"
/>
<TextView
android:id="@+id/phoneLabel"
android:text="@string/phone"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginRight="4dp"
android:layout_below="@+id/Giver"
/>
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:id="@+id/debtorPhone"
android:layout_below="@+id/debtorNames"
android:layout_toRightOf="@+id/phoneLabel"
android:text=""
/>
<TextView
android:id="@+id/labelAmount"
android:text="@string/amount"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginRight="4dp"
android:layout_below="@+id/debtorPhone"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/debtorAmount"
android:text=""
android:layout_toRightOf="@id/labelAmount"
android:layout_below="@+id/debtorPhone"
/>
<TextView
android:id="@+id/labelDueDate"
android:text="@string/dueDate"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginRight="4dp"
android:layout_below="@+id/debtorAmount"
/>
<TextView
android:text=""
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/dueDate"
android:layout_toRightOf="@+id/labelDueDate"
android:layout_below="@id/debtorAmount"
/>
<TextView
android:id="@+id/labelPayment"
android:text="@string/timeToPay"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginRight="4dp"
android:layout_below="@+id/dueDate"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/paymentDate"
android:layout_toRightOf="@id/labelPayment"
android:layout_below="@id/dueDate"
/>
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</FrameLayout>
我想删除第二个并用它下面的LinearLayout
替换它<Relativelayout>
JAVA代码
View view = inflater.inflate(R.layout.recyclerview, container, false);
recyclerView = view.findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(context)); //replace this with RelativeLayout
解决方案
推荐阅读
- dart - How can I create Page Indicator inside DefaultTabController without TabBar Widget?
- spring-boot - 为什么当休息模板抛出异常时没有调用自定义休息错误处理程序?
- python - 我将十六进制数据存储在 str 类型的列表中(例如:'0x15'),如何将列表中的 str 转换为 int 类型
- php - 通过 PHP 执行 2 个查询
- google-cloud-platform - GCP VM 无法启动或移动 TERMINATED 实例
- r - How to melt a multiple columns df with R?
- javascript - JS如何获取中心高的x/y坐标?
- shiny - shinyapps.io 上的应用程序行为
- python - 在 Python 中从 MP4 数据字节中提取波形
- javascript - Scraping information from specific remote site PHP