0

ich die folgende Benutzeroberfläche implementieren muß: enter image description hereTextview in RelativeLayout falscher Ausrichtung

Hierzu Ich bin mit dem folgenden Aufbau:

<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> 

In dem Image I Bild ist Laden aus einem mit Picasso URL Ich werde in den meisten Geräten korrekt ausgegeben, aber in einigen Geräten, auf denen Android weniger als Lollipop läuft, wird dies wie im Screenshot unten angezeigt. Der Text wird oben statt unten angezeigt. Aber ich habe android:layout_alignParentBottom="true" für das TextView gesetzt. Die RelativeLayout wird korrekt gerendert und passt auf das Bild (es hat einen Hintergrundgradienten, der am unteren Bildrand deutlich zu sehen ist).

enter image description here

Was dieses Problem verursacht, und wie kann ich dieses Problem lösen?

+1

android: layout_alignParentBottom = "true" für news0_cell_image_overlay_layout – Raj

Antwort

1

können Sie versuchen, mit FRAMELAYOUT

FrameLayout entworfen wird auf dem Bildschirm eine Fläche zu blockieren ein einzelnes Element angezeigt werden soll. Im Allgemeinen sollte FrameLayout eine einzelne untergeordnete Ansicht enthalten, da es schwierig sein kann, untergeordnete Ansichten in einer Weise zu organisieren, die auf verschiedene Bildschirmgrößen skalierbar ist, ohne dass sich die untergeordneten Elemente gegenseitig überlappen.

<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

Ich brauche die RelativeLayout einen Hintergrund hinzuzufügen. –

+1

'android: background =" @ drawable/news_cell0_overlay_gradient "' Dieser Teil ist wichtig –

+0

@HarikrishnanT gut, Siehe http://www.android-examples.com/overlap-view-by-putting-another-view-above-in -relativayout-android/ –

1

Sie dieses Layout versuchen können,

<?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

Ich brauche die RelativeLayout, um einen Hintergrund hinzuzufügen. –

+0

'android: background =" @ drawable/news_cell0_overlay_gradient "' Dieser Teil ist wichtig –

Verwandte Themen