我正在尝试创建一个CardView,它将显示作者的引用,包括作者姓名,引用,然后是它下面的引用.我想我已经掌握了大部分内容,但似乎对齐TextViews的一般规则似乎并不适用于CardView.我在这里研究过,发现你应该添加android:layout="vertical"到LinearLayout(或RelativeLayout),但这似乎并没有改变我的想法.我也尝试将它添加到CardView本身,认为它继承了直接父母的方向,但也没有运气.我仍然让TextViews相互重叠,而不是一个接一个地重叠.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent">
... >
<!-- A CardView that contains a TextView -->
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:longClickable="true"
android:orientation="vertical"
card_view:cardUseCompatPadding="true"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="4dp"
card_view:contentPadding="10dp"
>
<TextView
android:id="@+id/info_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FF4444"
android:textSize="24sp"
android:text="Gordon B. Hinckley"
/>
<TextView
android:id="@+id/info_text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/info_text"
android:text="Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test …Run Code Online (Sandbox Code Playgroud) 我有一个简单的RecyclerView,我想在onClick上删除这些项目.我一直遇到崩溃,这取决于我点击列表中的某些项目时出现上述错误.如果您遇到类似的问题,我的解决方法如下:
android ×2