[英]FrameLayout inside RelativeLayout not showing
我有以下问题。 在用作列表项的布局中,我在RelativeLayout
内有一个FrameLayout
。 在Eclipse的图形布局中,它的显示与预期的一样,但是,当我在真实设备(在这种情况下为HTC One V Android 4.0.3)中进行调试时, FrameLayout
根本不会出现(但是它占据的区域是可见的) 。 在适配器中,我不使用可见性,而只是在两种颜色之间更改背景颜色。
这是我的布局代码:
<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>
在我的适配器中,我与布局进行交互以更改颜色的部分( 并且确保您是与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));
图形布局显示以下内容,这是正确的
但是,当我进行调试时,将出现以下内容( 箭头和边框显示了应该显示颜色的区域,但是只显示了宽度 )
在此先感谢您,因为我不知道还能检查什么。
使用FrameLayout的前景色属性(无子级)代替背景,或将View(fill_parent)添加到FrameLayout或将FrameLayout的paddingLeft设置为15dp(与您的宽度相同)
除非有理由给自己尺寸,否则FrameLayout会将自己测量为0。 layout_widith / height仍在保留其空间,但是它没有要绘制的子级,并且您的背景是一种颜色(因此它是无量纲的)
尝试layout_alignParentLeft =“ true”,添加一些用于测试Framelayout的边距,然后使用文本框作为参考
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.