设置背景颜色时不显示Imageview

时间:2013-11-30 10:43:25

标签: android xml android-layout

XML文件的结构是:

FrameLayout 
    ImageView
    LinearLayout
        TextView
        TextView

当我使用LinearLayout的背景颜色时,不会出现ImageView的drawable。如果我从LinearLayout中移除了bg颜色,那么drawable就在它的位置。

我在这样的代码中添加了drawable:

              if( placetype == 0 )  {
                    ImageView im0 = (ImageView) myContentsView.findViewById(R.id.infowindow_imageview);
                    int imageResource0 = R.drawable.beer_white;
                    im0.setImageResource(imageResource0);
                } else if( placetype == 1 ) { 
                     //etc ... 

和XML代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content"    android:orientation="vertical"  >

<FrameLayout
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:focusable="true"
    android:foreground="?activatableItemBackground"
    android:id="@+id/map_info_top"  >     
          <ImageView
              android:id="@+id/infowindow_imageview"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="top|right"
              android:layout_marginRight="-12dp"
              android:layout_marginTop="-12dp"
              android:adjustViewBounds="true"
              android:alpha="0.3"
              android:contentDescription="@null"
              android:scaleType="fitXY" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/red_drink"
                android:orientation="vertical" >

                    <TextView
                        style="@style/TextHeader"
                        android:id="@+id/custom_infowindow_title"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:textStyle="bold"

                        android:paddingLeft="8dp"
                        android:paddingRight="8dp"
                        android:paddingBottom="8dp"     />

                    <TextView
                        style="@style/TextHeaderSub"
                        android:text="Click to Read more"                           
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"

                        android:paddingLeft="8dp"
                        android:paddingRight="8dp"
                        android:paddingBottom="8dp"
                         />

            </LinearLayout>     

</FrameLayout>


</LinearLayout>

由于ImageView和LinearLayout位于FrameLayout中,我认为重叠视图不会出现问题。 有人可以解释一下我在这里做错了什么吗?

1 个答案:

答案 0 :(得分:2)

您的LinearLayout是在ImageView上绘制的。由于背景不透明,您无法看到图像。尝试将ImageView放在LinearLayout下面的XML资源

相关问题