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”' 这部分很重要 –

相关问题