I have the following issue. In my layout, which is used as a list item, I have a FrameLayout
inside a RelativeLayout
. 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). 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:
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 will measure itself as 0 unless it has a reason to give itself dimension. 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_alignParentLeft =“ true”,添加一些用于测试Framelayout的边距,然后使用文本框作为参考
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.