有什么问题?
:在上图中,您可以看到浮动图标或视图未正确对齐的第3项,如您在其他项目中看到的那样。
:每次打开此屏幕时,某些项目的锚点视图都无法正确对齐。
我做了什么?
我使用GridLayout管理器实现了Recycler。
//setting Grid layout
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, ROW_COUNT, LinearLayoutManager.VERTICAL, false);
mRecyclerView.setLayoutManager(gridLayoutManager);
和自定义适配器。
项目布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="250dp"
android:padding="1dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ImageView
android:id="@+id/service_image"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="centerCrop"
android:src="@drawable/dummy_image"/>
<LinearLayout
android:id="@+id/service_description"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/COLOR.teal_green"
android:orientation="vertical"
android:padding="16dp"
>
<mychatapplication.view.custom.CustomTextView
android:id="@+id/service_topic_title"
style="@style/customCommonFont_regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="8dp"
android:maxLines="3"
android:text="Android tutorial text"
android:textColor="@color/white"
android:textSize="16sp"/>
<mychatapplication.view.custom.CustomTextView
android:id="@+id/service_topic_author"
style="@style/customCommonFont_regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:gravity="center"
android:maxLines="3"
android:text="Jugal kishor joshi"
android:textColor="@color/color_background_chat_text_view"
android:textSize="12sp"
/>
<mychatapplication.view.custom.CustomTextView
android:id="@+id/service_topic_interest"
style="@style/customCommonFont_regular"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="left"
android:layout_weight="1"
android:gravity="center_horizontal|bottom"
android:text="Follow"
android:textAllCaps="true"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold"
/>
</LinearLayout>
</LinearLayout>
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="16dp"
android:src="@drawable/user_profile_image_dummy"
app:civ_border_color="@color/white"
app:civ_border_width="2dp"
app:layout_anchor="@id/service_description"
/>
</android.support.design.widget.CoordinatorLayout>
答案 0 :(得分:0)
尝试将代码修改为:
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="16dp"
android:src="@drawable/user_profile_image_dummy"
app:civ_border_color="@color/white"
app:civ_border_width="2dp"
app:layout_anchor="@id/service_description"
app:layout_anchorGravity="bottom|start"
/>
包含app:layout_anchorGravity="bottom|start"