0

我有一个网格视图。我有自定义视图的简单网格适配器, 但该自定义视图隐藏图像,但我可以在Eclipse图形布局视图中看到视图。但是当我运行它时,它隐藏了一张图片Android相对布局隐藏我的图片视图

custom grid item layout : 

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

     <RelativeLayout 
      android:id="@+id/gridviewlayout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/grid_item_selector" > 

      <ImageView 
       android:id="@+id/picture" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_above="@+id/text" 
       android:layout_alignParentTop="true" 
       android:layout_centerHorizontal="true" 
       android:layout_marginBottom="5dp" 
       android:padding="5dp" 
       android:src="@drawable/ic_launcher" /> 

      <TextView 
       android:id="@+id/text" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_marginTop="10dp" 
       android:gravity="center" 
       android:paddingBottom="5dp" 
       android:singleLine="true" 
       android:text="settings" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textColor="@color/black" 
       android:textStyle="bold" /> 
     </RelativeLayout> 

    </LinearLayout> 
+2

如果这些是你的布局中唯一的组件,那么你的根标签'linearLayout'似乎对我毫无意义,将其删除。 – Apurva 2015-04-03 07:21:39

+1

正如@Apurva正确指出的那样,你有一个**无用的**(这对表演不利)'布局嵌套'。请移除LinearLayout父项。 – 2015-04-03 07:25:42

+0

谢谢u @Apurva,但实际上线性布局用于动态改变bg颜色,并且相对有选择器,所以我需要使用Linear layout ... 因为使用动态颜色我无法更改bg颜色否? 使线性使用.. – 2015-04-03 10:20:06

回答

2

请检查您的错误日志为自定义网格项目布局xml,我已检查您的代码与示例它给我输出。 可能是您的图片已损坏。检查您的drawable/ic_launcher文件或您的资源文件夹替换为另一个图像并尝试。

+0

嘿非常感谢你...我得到了一个答案... ic_launcher被破坏了..谢谢你 – 2015-04-03 10:13:20

+0

你最欢迎... – 2015-04-03 10:26:50

0

请分享你想要什么样的视图和。当您使用RelativeLayout它一定会隐藏一些看法 - Layout_rightof,Layout_above通过设置这些属性可以设置适当的意见

For example:

<ImageButton 
     android:id="@+id/imgMenu" 
     android:layout_width="..." 
     android:layout_height="..." 
     android:layout_gravity="..." 
     android:background="@drawable/bottom_key" 
     ... /> 

    <TextView 
     android:id="..." 
     android:layout_width="..." 
     android:layout_toRightOf="@+id/imgMenu" 
     android:layout_height="..." 
     android:layout_marginLeft="10dp" 
     android:gravity="center" 
      /> 

以上内容显示Textview是对我的ImageView的。

- 你好试试你的Imageview固定的高度和宽度检查会发生什么。

+0

我无法发布图像,因为我有较少的声誉...所以 – 2015-04-03 08:41:52

+0

,你可以看到,布局具有简单的代码,只有一些属性 – 2015-04-03 08:44:28

+0

但由于你的代码中的相对布局,它隐藏你的imageview设置正确! – Hardy 2015-04-03 09:00:59

0
  1. 删除不必要的LinearLayout

  2. 通过FrameLayout包装你ImageView为:

    <FrameLayout 
        android:layout_width="48dp" 
        android:layout_height="48dp" 
        android:layout_above="@+id/text" 
        android:layout_alignParentTop="true" 
        > 
    
    <ImageView 
        android:id="@+id/picture" 
        android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:adjustViewBounds="true" 
         android:layout_gravity="center" 
         android:gravity="center" 
         android:layout_marginBottom="5dp" 
         android:padding="5dp" 
         android:src="@drawable/ic_launcher" /> 
    
    </FrameLayout> 
    

希望这有助于!

+0

实际上,线性布局用于更改背景颜色... 相对布局有选择器和线性只有背景颜色。 – 2015-04-03 08:43:12

+0

而我用这个框架布局的乌尔代码,但它仍然显示相同的输出... 它隐藏该imageview – 2015-04-03 08:55:57

+0

你可以尝试'frameLayout'具有特定的大小,看我的答案 – Xcihnegn 2015-04-03 09:21:03