3

Я разрабатываю приложение, и я сделал ниже показанный макет:Как принести ImageView через CardView? Пожалуйста, смотрите подробности

enter image description here

Существует CircleImageView и CardView.

Вот код XML:

<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="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.playrapp.playr.Profile" 
    tools:showIn="@layout/activity_profile"> 

    <android.support.v7.widget.CardView 
     android:id="@+id/profileCard" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     app:contentPadding="10dp"> 

</android.support.v7.widget.CardView> 

    <de.hdodenhof.circleimageview.CircleImageView 
     android:id="@+id/userImageProfile" 
     android:layout_width="150dp" 
     android:layout_height="150dp" 
     android:layout_marginTop="50dp" 
     android:src="@mipmap/ic_launcher" 
     android:layout_centerHorizontal="true"/> 

</RelativeLayout> 

Здесь cardview находится над ImageView. Я хочу, чтобы изображение было просмотрено. Как я могу это сделать?

Пожалуйста, дайте мне знать.

+0

обернуть его в соске LinearLayout –

ответ

1

CardView имеет установленный по высоте набор app:elevation="0dp" в xml-файле.

+0

это сделало работу, но cardview не смотрите как карту больше! :/ –

+0

как вы это понимаете? вы могли бы поделиться скриншотом? – Katharina

+0

Только один вопрос - почему вы хотите разместить изображение поверх карты? Не могли бы вы просто положить его внутрь? – Katharina

4

Высота над уровнем моря CardView больше чем CircleImageView. Таким образом, вы должны установить более высокую отметку до CircleImageView, чтобы показать ее более CardVew.

Набор CardView высота в app:cardElevation="4dp" и установить CircleImageView высоту, как android:elevation="8dp"

Вот рабочий код XML. Попробуйте это:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <android.support.v7.widget.CardView 
     android:id="@+id/profileCard" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_margin="16dp" 
     app:cardCornerRadius="4dp" 
     app:cardElevation="4dp" 
     app:cardUseCompatPadding="false" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      android:gravity="center_horizontal" 
      android:layout_marginTop="75dp" 
      android:padding="24dp"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Hammad Nasir" 
       android:textSize="32sp" 
       android:textColor="#727272"/> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="\@hammadnasir" 
       android:textSize="24sp" 
       android:textColor="#727272" /> 

     </LinearLayout> 
    </android.support.v7.widget.CardView> 


    <de.hdodenhof.circleimageview.CircleImageView 
     android:id="@+id/userImageProfile" 
     android:layout_width="150dp" 
     android:layout_height="150dp" 
     android:layout_marginTop="75dp" 
     android:layout_centerHorizontal="true" 
     android:src="@mipmap/ic_launcher" 
     android:elevation="8dp" /> 

</RelativeLayout> 

ВЫВОД:

enter image description here

Надеется, что это поможет ~