2016-11-13 77 views
1

我是Android开发的新手。 尝试将Button和ImageView放入FrameLayout中,但它们不可见(它们确实存在于布局上,但未绘制)。FrameLayout中的元素不可见

我的布局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/OuterFrame" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:foreground="@drawable/flb1_off"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/show_dialog" 
     android:id="@+id/showDialogBtn" 
     android:onClick="showDialog" 
     android:layout_gravity="center" 
     android:background="#123456" 
     android:textColor="@color/abc_background_cache_hint_selector_material_dark" 
     android:visibility="visible" /> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/flb" 
     android:layout_gravity="bottom" 
     android:contentDescription="@string/content_desc" /> 

</LinearLayout> 

中的API版本是19 有趣的是,按钮clickHandler事件工作正常,但按钮本身是无形的。

我把所有的孩子都看成是单身孩子,如here所述,但没有成功。

我在做什么错了?

+2

我觉得'android:foreground =“@ drawable/flb1_off”'是问题所在。 –

+0

@SHAHMDMONIRULISLAM,你是对的! android:foreground替换android:background修复它! – Nicolas

+0

我已经添加了答案。你能接受吗? @Nicolas –

回答

0

您的问题是从这一行来:

android:foreground="@drawable/flb1_off" 

你需要去改变它。