2017-06-16 206 views
1

我正在尝试重新创建一个类似于这个卡片视图的顶级图片,然后是一些数据,也许下面是一些动作按钮。但对于我的生活,我无法让文字置于图像之上。 enter image description herexamarin卡片视图布局

这里是我迄今为止

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:cardview="http://schemas.android.com/apk/res-auto" 
android:id="@+id/card_view" 
android:layout_width="match_parent" 
android:layout_height="325dp" 
android:layout_margin="8dp"> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <ImageView 
     android:id="@+id/image1" 
     android:layout_width="match_parent" 
     android:layout_height="230dp" 
     android:layout_alignParentTop="true" 
     android:scaleType="centerCrop" /> 
    <TextView 
     android:id="@+id/recipeName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/image1" 
     android:maxLines="3" 
     android:padding="8dp" 
     android:text="name" 
     android:textColor="#222" 
     android:textStyle="bold" 
     android:textSize="22dp" /> 
    <TextView 
     android:id="@+id/description" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/recipeName" 
     android:maxLines="3" 
     android:padding="8dp" 
     android:text="description" 
     android:textColor="#666" 
     android:textSize="14dp" /> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_below="@+id/description"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/recipeName" 
      android:maxLines="3" 
      android:padding="8dp" 
      android:text="View" 
      android:textColor="#666" 
      android:textSize="14dp" /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/recipeName" 
      android:maxLines="3" 
      android:padding="8dp" 
      android:text="Add" 
      android:textColor="#666" 
      android:textSize="14dp" /> 
    </LinearLayout> 
</RelativeLayout> 

+1

你是指textview的图层吗?你能给我们从你的应用截图来获得更好的印象吗? –

回答

2

我会假设你想@+id/recipeName@+id/image1顶部。

recipeName,您已设置:android:layout_below="@+id/image1"将布局元素下面image1。因为您不希望它在该元素下面,请删除该行。尝试android:layout_alignBottom="@+id/image1"。我们有足够的布局参数办最多的事:LayoutParams,尽管它可以是一个有点兔子洞,一旦你开始做复杂的布局......

而且你有layout_below上的元素你LinearLayout里面哪些不会做任何事情。

+0

是试图让食谱名称在图像的底部。我会检查你提到的各种布局参数。谢啦。 –

+0

是的,这个伎俩。再次感谢。 –