0

je dois mettre en œuvre l'interface suivante: enter image description hereTextView dans un mauvais alignement RelativeLayout

Pour cela, je me sers de la mise en page suivante:

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:color/white"> 
    <ImageView 
     android:id="@+id/news_image0" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:minHeight="@dimen/news_cell0_imageview_min_height" 
     android:adjustViewBounds="true" 
     android:scaleType="fitXY" /> 
    <RelativeLayout 
     android:id="@+id/news0_cell_image_overlay_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignBottom="@+id/news_image0" 
     android:layout_alignTop="@+id/news_image0" 
     android:layout_alignLeft="@+id/news_image0" 
     android:layout_alignStart="@+id/news_image0" 
     android:layout_alignEnd="@+id/news_image0" 
     android:layout_alignRight="@+id/news_image0" 
     android:background="@drawable/news_cell0_overlay_gradient"> 
     <TextView 
      android:id="@+id/news_title0" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:gravity="center_vertical|start" 
      android:layout_alignParentBottom="true" 
      android:maxLines="3" 
      android:ellipsize="end" 
      android:textColor="@color/colorNewsCellType0TitleText" 
      android:layout_margin="@dimen/news_cell0_textview_margin" 
      android:textSize="@dimen/news_cell0_title_text_size" 
      android:typeface="monospace" /> 
    </RelativeLayout> 
</RelativeLayout> 

Dans le ImageView je chargeais image à l'aide Picasso d'un URL Je reçois la sortie correctement dans la plupart des appareils, mais dans certains des appareils fonctionnant sous Android moins Lollipop, cela se présente comme la capture d'écran ci-dessous. Le texte apparaît en haut, au lieu de bas. Mais j'ai mis android:layout_alignParentBottom="true" pour le TextView. Le RelativeLayout est rendu correctement, et il correspond à l'image (il a un dégradé d'arrière-plan, qui peut être clairement vu au bas de l'image).

enter image description here

Quelle est la cause de ce problème et comment puis-je résoudre ce problème?

+1

android: layout_alignParentBottom = "true" pour news0_cell_image_overlay_layout – Raj

Répondre

1

Vous pouvez essayer avec FRAMELAYOUT

FrameLayout est conçu pour bloquer une zone sur l'écran pour afficher un seul élément. En règle générale, FrameLayout doit être utilisé pour contenir une seule vue enfant , car il peut être difficile d'organiser les vues enfant de manière pouvant être étendue à différentes tailles d'écran sans que les enfants se chevauchent.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <ImageView 
     android:src="@drawable/ic_launcher" 
     android:scaleType="fitCenter" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent"/> 

    <TextView 
     android:text="Hi.." 
     android:textSize="17sp" 
     android:textStyle="bold" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:gravity="center|bottom"/> 
</FrameLayout> 
+0

J'ai besoin RelativeLayout pour ajouter un arrière-plan. –

+1

'android: background =" @ drawable/news_cell0_overlay_gradient "' Cette partie est importante –

+0

@HarikrishnanT bien, Voir http://www.android-examples.com/overlap-view-by-putting-another-view-above-in -relativelayout-android/ –

1

Vous pouvez essayer cette mise en page,

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@android:color/white"> 

    <ImageView 
     android:id="@+id/news_image0" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:minHeight="100dp" 
     android:scaleType="fitXY"/> 

    <TextView 
     android:id="@+id/news_title0" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/news_image0" 
     android:layout_centerHorizontal="true" 
     android:ellipsize="end" 
     android:maxLines="3" 
     android:padding="12dp" 
     android:text="fsdsdfdsdsfsdfsdf" 
     android:textColor="#f00" 
     android:typeface="monospace"/> 
</RelativeLayout> 
+0

J'ai besoin de la RelativeLayout pour ajouter un arrière-plan. –

+0

'android: background =" @ drawable/news_cell0_overlay_gradient "' Cette partie est importante –