2015-02-12 131 views
0

我有一个列表项目布局,并且此布局用于StickyListHeaderListView,并在图像后面包含垂直分隔符。问题在于尽管在预览屏幕上绘制了视图分隔符,但从未在真实设备上绘制视图分隔符。XML垂直线不在真实设备上绘制

下面是XML布局代码

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:minHeight="80dp" 
     android:paddingLeft="@dimen/padding_medium" 
     android:paddingRight="@dimen/padding_medium" 
     tools:ignore="MissingPrefix"> 

<TextView 
    android:id="@+id/textview_date" 
    fontPath="@string/font_semi_bold" 
    android:layout_width="wrap_content" 
    android:maxWidth="60dp" 
    android:layout_height="match_parent" 
    android:layout_centerVertical="true" 
    android:gravity="center_vertical|right" 
    android:textAppearance="@android:style/TextAppearance.Holo.Medium" 
    android:textColor="#999999" 
    tools:text="21\nFeb" /> 

<RelativeLayout 
    android:id="@+id/container" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_toRightOf="@+id/textview_date" 
    android:minWidth="50dp" 
    android:paddingLeft="@dimen/padding_extra_small" 
    android:paddingRight="@dimen/padding_extra_small"> 

    <View 
     android:layout_width="1px" 
     android:layout_height="match_parent" 
     android:layout_centerHorizontal="true" 
     android:background="#999999" /> 
    <ImageView 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="@dimen/margin_small" 
     android:src="@drawable/test_event_cat_1" /> 
</RelativeLayout> 

<TextView 
    android:id="@+id/textview_event_name" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@+id/container" 
    android:layout_marginTop="@dimen/margin_small" 
    android:textColor="#999999" 
    fontPath="@string/font_medium" 
    tools:text="ACS Nights’ Soccer Finale" 
    android:textAppearance="@android:style/TextAppearance.Holo.Medium" /> 
<TextView 
    android:id="@+id/textview_interval" 
    android:layout_width="match_parent" 
    android:textAppearance="@android:style/TextAppearance.Holo.Small" 
    android:layout_alignLeft="@+id/textview_event_name" 
    android:layout_below="@id/textview_event_name" 
    android:layout_marginTop="@dimen/margin_small" 
    android:textColor="#999999" 
    tools:text="4:00 PM - 6:00 PM" 
    android:layout_height="wrap_content" /> 
</RelativeLayout> 

该代码中的Android Studio中

Android Studio Preview Output

预览窗口产生一个正确的布局,但在设备上的输出不包含任何垂直线如在预览中

Device output

我试着把垂直线放在布局的不同部分,但仍然没有显示在真实的设备上。 任何帮助,将不胜感激。

回答

0

如何添加一个新项目到你的listView?

是否每个项目都有整个xml文件的布局?

那么一行将使用整个layout.xml文件?

编辑:

我猜,因为你必须在你与线路相对布局2次,图像推离屏幕的行。 我花了一段时间找到一些参考资料,但here

RelativeLayout以相同的方式工作,相对布局中的最后一幅图像获胜。

所以你必须找到一种方法,你可以在图像的顶部绘制图像。或者你可以绘制一个简单的线条作为drawable,并将其设置为包含图像的relativeLayout的背景

+0

我使用 添加新项目mAdapter.addAll(events); mAdapter.notifyDataSetChanged(); - 每一个项目是对整个XML文件 的布局 - 是 – 2015-02-12 00:42:33

+0

你在哪里设置用于列表视图的每一行的布局? – 2015-02-12 00:44:22

+0

在适配器的getView方法中 – 2015-02-12 00:46:01

0

我将RelativeLayout中的根改为水平LinearLayout,并且在做了必要的布局更改之后,问题就解决了!

我读过somewhere是RelativeLayout的,其父母为一个ListView时match_parent高度分配有问题。