我有带有卡片视图的recyclerView。
在cardView布局中,我要在心脏图像旁边添加文本并共享图像。我想如果文本很长,那么不要在心脏图像后面,而是应该换行。现在,它无法按我的意愿工作。另外,在其他卡片视图中,我的心脏图像有时会比其他心脏更大。
这是一个示例(上方的心和共享大于下方的心,我想要所有的心并共享相同大小的图像):
我的卡视图布局代码:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FCFCFC"
tools:context="showresultactivity.SlideTabsActivity">
<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="3dp"
app:cardElevation="1dp"
android:layout_margin="5dp"
app:cardPreventCornerOverlap="false">
<RelativeLayout
android:id="@+id/relativeLayout"
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imagesSrcUrl"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/ic_launcher"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/someText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/someText"
android:layout_below="@id/street"
android:text="some"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="@+id/someText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/imagesSrcUrl"
android:layout_below="@id/someText2"
android:textSize="12dp"
android:text="some text "
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
/>
<TextView
android:id="@+id/street"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12dp"
android:layout_alignParentTop="true"
android:layout_alignRight="@id/cardViewLike"
android:layout_toRightOf="@+id/imagesSrcUrl"
android:text="asdasd sd sd ad ssssssowiskifd sdf"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:drawableLeft="@drawable/custom_size_icon_next_to_text"
android:textAlignment="gravity"
/>
<ImageView
android:id="@+id/cardViewLikeRed"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignBottom="@+id/street"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="35dp"
android:src="@drawable/ic_heart_red"
/>
<ImageView
android:id="@+id/cardViewLike"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignBottom="@+id/street"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="35dp"
android:src="@drawable/ic_heart_white"
/>
<ImageView
android:id="@+id/cardViewShare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@+id/street"
android:background="@null"
android:tintMode="src_over"
android:src="@drawable/ic_share" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
有时候这种情况会发生:
文字在我的图片下面,但随后应该换行。
您需要更改街道TextView的相对规则
尝试添加以下内容:
android:layout_toEndOf="@+id/imagesSrcUrl"
android:layout_toLeftOf="@+id/cardViewLikeRed"
android:layout_toRightOf="@+id/imagesSrcUrl"
android:layout_toStartOf="@+id/cardViewLikeRed"
因此,您的TextView应该如下所示:
<TextView
android:id="@+id/street"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_toEndOf="@+id/imagesSrcUrl"
android:layout_toLeftOf="@+id/cardViewLikeRed"
android:layout_toRightOf="@+id/imagesSrcUrl"
android:layout_toStartOf="@+id/cardViewLikeRed"
android:drawableLeft="@drawable/custom_size_icon_next_to_text"
android:text="asdasd sd sd ad ssdsdhjshjshkkljkljkljkljlkjkljlkjkljlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjljlkjlkjlkjkljlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjljlkjlkjdjkshjdhsdjkhjkdshfjksdhfssssowiskifd sdf"
android:textAlignment="gravity"
android:textSize="12dp" />
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句