0

我需要實現以下界面: enter image description here的TextView在RelativeLayout的不適當的對準

對於這一點,我現在用的是以下佈局:

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

走進我從一個加載使用畢加索圖像的ImageView URL。我在大多數設備上都能正確獲得輸出,但在運行Android的設備中,某些設備比Lollipop少,因此會顯示如下截圖。文本顯示在頂部,而不是底部。但是我爲TextView設置了android:layout_alignParentBottom="true"RelativeLayout呈現正確,它適合圖像(它有一個背景漸變,可以清楚地看到在圖像的底部)。

enter image description here

是什麼原因造成這個問題,我怎麼能解決這個問題?

+1

機器人:layout_alignParentBottom = 「真」 爲news0_cell_image_overlay_layout – Raj

回答

1

您可以FRAMELAYOUT

FrameLayout裏被設計來阻擋的區域在屏幕上顯示 單個項目嘗試。一般來說,FrameLayout應該用於保存子視圖,因爲可以很難以 的方式組織子視圖,這種方式可以擴展到不同的屏幕尺寸,而不需要兒童 彼此重疊。

<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

我需要的RelativeLayout添加背景。 –

+1

'android:background =「@ drawable/news_cell0_overlay_gradient」'這部分很重要 –

+0

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

1

你可以試試這個佈局,

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

我需要RelativeLayout來添加背景。 –

+0

'android:background =「@ drawable/news_cell0_overlay_gradient」' 這部分很重要 –

相關問題