2017-10-04 7 views
0

Je construis ma mise en page personnalisée pour mon application Android et j'essaye d'ajouter l'élévation à un LinearLayout mais ça ne marche pas, j'ai essayé beaucoup de solutions trouvées sur le web mais rien avec Succès.Elevation ne fonctionne pas sur LinearLayout

Mon xml est la suivante:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:orientation="horizontal" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:padding="10dp"> 

<de.hdodenhof.circleimageview.CircleImageView 
    android:layout_width="40dp" 
    android:layout_height="40dp" 
    android:src="@drawable/admin_gray" 
    app:civ_border_width="2dp" 
    app:civ_border_color="@android:color/darker_gray" 
    android:layout_marginRight="10dp"/> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/tvNewsAggiuntoCommentoDescrizione" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Username ha commentato una ricetta:"/> 

     <TextView 
      android:id="@+id/tvNewsAggiuntoCommentoData" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="25/05/1989 12:58:07" 
      android:textColor="@android:color/darker_gray" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:background="@color/white" 
     android:elevation="10dp"> 

     <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical" android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/rounded_linear_layout_tile_ricetta" 
      android:layout_marginBottom="5dp" 
      > 

      <ImageView 
       android:id="@+id/imageViewRicetta" 
       android:layout_width="match_parent" 
       android:layout_height="150dp" 
       android:src="@mipmap/cibo" 
       android:scaleType="centerCrop"/> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Antipasto" 
       android:background="@color/colorCategoriaRicetta" 
       android:layout_alignBaseline="@id/imageViewRicetta" 
       android:layout_gravity="right|top" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textColor="@android:color/white" 
       android:padding="3dp" 
       android:id="@+id/tvCategoriaRicetta" 
       android:elevation="4dp"/> 

      <TextView 
       android:id="@+id/tvTitoloRicetta" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Maxi hamburger con maionese" 
       android:background="@color/colorBackgroundTextViewNomeRicetta" 
       android:layout_alignBaseline="@id/imageViewRicetta" 
       android:layout_gravity="left|bottom" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:textColor="@android:color/white" 
       android:paddingLeft="5dp" 
       android:textStyle="bold" /> 

     </FrameLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <de.hdodenhof.circleimageview.CircleImageView 
       android:id="@+id/imageViewFotoAltroUtente" 
       android:layout_width="40dp" 
       android:layout_height="40dp" 
       android:layout_marginRight="10dp" 
       android:layout_marginLeft="10dp" 
       android:src="@drawable/admin_gray" 
       app:civ_border_width="2dp" 
       app:civ_border_color="@android:color/darker_gray" /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:padding="5dp"> 

       <TextView 
        android:id="@+id/tvUsernameUtenteCommento" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:textStyle="bold" 
        android:text="Username"/> 

       <TextView 
        android:id="@+id/tvNewsAggiuntoCommentoCommento" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Questo è il testo di esempio di un commento a una ricetta"/> 

      </LinearLayout> 

     </LinearLayout> 

    </LinearLayout> 


</LinearLayout> 

Attention, la mise en page avec l'altitude est pas le top LinearLayout, c'est la mise en page avec l'attribut "élévation" ...

Pouvez-vous aider moi de trouver une solution pour obtenir l'élévation correctement?

Merci beaucoup.

+0

Pouvez-vous donner un exemple capture d'écran mockup de ce vous voulez que les résultats ressemblent? –

+0

La meilleure façon d'utiliser l'élévation est dans une cardview. Sinon, c'est trop bogué. – AeriaGlorisia

Répondre

0

Ajouter cette propriété vous LinearLayout:

android:outlineProvider="bounds" 

Assurez-vous que tous les parents de vue de l'élément que vous voulez pour définir l'élévation n'a pas de rembourrage. Cela peut entraîner l'écrêtage de l'ombre. Une solution pour cela est d'ajouter cette propriété à tous vue parent:

android:clipToPadding="false" 

En outre, les ombres ne montreront pas si vous avez cette ligne dans le manifeste:

android:hardwareAccelerated="false" 
+0

Salut @GuilhermeFGL, merci pour votre réponse, j'ai inséré votre ligne sur LL et je n'ai pas la ligne dans le manifeste, de toute façon cela ne fonctionne pas ... –

+0

Quelle est la version de l'API que vous utilisez pour tester le vue? – GuilhermeFGL

+0

C'est API 24 (Android 7.0) –