【发布时间】:2017-12-08 10:39:21
【问题描述】:
现在,我有一个 RecyclerView 和多个 CardView 来显示我的项目。
我的 CardView 有一个 RelativeLayout,我在其中添加了一些 ImageView(在本例中为 3 个,但可以更多)。
我的每个项目都会有一个图片列表来显示,假设#item1 有 Facebook、Twitter 和 Youtube,但#item2 只有 Facebook 和 Youtube 图片。
我应该如何对齐图像?如果我只是删除 Twitter 图片,我需要将我的 Facebook 图片的 layout_toLeftOf 更新为 Youtube 图片。
我认为我不应该对我所有的物品都做这种逻辑,它会超过权力......
示例图片: https://i.stack.imgur.com/uJZTi.png
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
card_view:cardCornerRadius="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/card_height"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal">
<ImageView
android:id="@+id/coverImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:scaleType="centerCrop"
/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="end|top">
<ImageView android:background="@null"
android:id="@+id/facebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/facebook_icon"
android:layout_toLeftOf="@+id/twitter"/>
<ImageView android:background="@null"
android:id="@+id/twitter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/twitter_icon"
android:layout_toLeftOf="@+id/youtube"/>
<ImageView android:background="@null"
android:id="@+id/youtube"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/youtube_icon"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left|bottom"
android:background="@android:drawable/screen_background_dark_transparent"
android:orientation="vertical">
<TextView
android:id="@+id/titleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:textSize="@dimen/text_size"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
【问题讨论】: