簡體   English   中英

RelativeLayout中的FrameLayout不顯示

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM