2017-06-16 208 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

是的,這個伎倆。再次感謝。 –