简体   繁体   English

RelativeLayout中的FrameLayout不显示

[英]FrameLayout inside RelativeLayout not showing

I have the following issue. 我有以下问题。 In my layout, which is used as a list item, I have a FrameLayout inside a RelativeLayout . 在用作列表项的布局中,我在RelativeLayout内有一个FrameLayout In the Graphical Layout in Eclipse it appears just as expected, however, when I debug in a real device (HTC One V Android 4.0.3 in this case), the FrameLayout does not appear at all (but the area it occupies is visible). 在Eclipse的图形布局中,它的显示与预期的一样,但是,当我在真实设备(在这种情况下为HTC One V Android 4.0.3)中进行调试时, FrameLayout根本不会出现(但是它占据的区域是可见的) 。 In the Adapter I do not play with the visibility, I just change the background color between two colors. 在适配器中,我不使用可见性,而只是在两种颜色之间更改背景颜色。

Here is my layout code: 这是我的布局代码:

<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="130dp" >

<FrameLayout
    android:id="@+id/entryType"
    android:layout_width="15dp"
    android:layout_height="match_parent"
    android:background="@color/color_punch_in_darker"
    android:gravity="center" >
</FrameLayout>

<TextView
    android:id="@+id/time"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginRight="10dp"
    android:layout_marginTop="3dp"
    android:gravity="center"
    android:singleLine="true"
    android:textColor="@color/color_black"
    android:textSize="21sp"
    android:textStyle="bold" />

<ImageView
    android:id="@+id/clock"
    android:layout_width="20dp"
    android:layout_height="20dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="7dp"
    android:layout_toLeftOf="@id/time"
    android:src="@drawable/ic_clock" />

<TextView
    android:id="@+id/company"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="5dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="10dp"
    android:layout_toLeftOf="@id/clock"
    android:layout_toRightOf="@id/entryType"
    android:ellipsize="end"
    android:gravity="left|top"
    android:hint="@string/string_NA"
    android:singleLine="true"
    android:textColor="@color/color_grey_darker"
    android:textSize="18sp" />

<TextView
    android:id="@+id/project"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_below="@id/company"
    android:layout_marginBottom="5dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_toRightOf="@id/entryType"
    android:ellipsize="end"
    android:gravity="left|top"
    android:hint="@string/string_NA"
    android:singleLine="true"
    android:textColor="@color/color_grey_darker"
    android:textSize="18sp"
    android:textStyle="bold" />

<TextView
    android:id="@+id/note"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_alignParentRight="true"
    android:layout_below="@id/project"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_toRightOf="@id/entryType"
    android:ellipsize="end"
    android:gravity="left|top"
    android:hint="@string/string_NA"
    android:textColor="@color/color_grey_darker"
    android:textSize="18sp"
    android:textStyle="italic" />

</RelativeLayout>

In my adapter, the part where I interact with the layout for changing the color ( and I assure you is the only part of the code where I interact with the R.id.entryType view ), I have the following code: 在我的适配器中,我与布局进行交互以更改颜色的部分( 并且确保您是与R.id.entryType视图进行交互的代码的唯一部分 ),我具有以下代码:

if(entry.isInEntry())
    viewHolder.entryType.setBackgroundColor(getContext().getResources().getColor(R.color.color_punch_in_darker));
else
    viewHolder.entryType.setBackgroundColor(getContext().getResources().getColor(R.color.color_punch_out_darker));

The Graphical layout shows the following, which is the correct 图形布局显示以下内容,这是正确的

图形布局图像

But when I debug, the following appears ( the arrow and the border shows the area where the color should be, but instead only the width appears ) 但是,当我进行调试时,将出现以下内容( 箭头和边框显示了应该显示颜色的区域,但是只显示了宽度

调试布局

Many thanks in advance since I do not know what else I can check. 在此先感谢您,因为我不知道还能检查什么。

Use foreground attribute for FrameLayout (with no children) instead of background or add a View (fill_parent) to the FrameLayout or set the FrameLayout's paddingLeft to 15dp (same as your width) 使用FrameLayout的前景色属性(无子级)代替背景,或将View(fill_parent)添加到FrameLayout或将FrameLayout的paddingLeft设置为15dp(与您的宽度相同)

FrameLayout will measure itself as 0 unless it has a reason to give itself dimension. 除非有理由给自己尺寸,否则FrameLayout会将自己测量为0。 The layout_widith/height is still reserving it space, but it has no children to draw and your background is a color (therefore it's dimensionless) layout_widith / height仍在保留其空间,但是它没有要绘制的子级,并且您的背景是一种颜色(因此它是无量纲的)

尝试layout_alignParentLeft =“ true”,添加一些用于测试Framelayout的边距,然后使用文本框作为参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM