相对布局中的另一个小部件
Widget next to another in relativelayout
我有带卡片视图的 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" />
我有带卡片视图的 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" />