简体   繁体   中英

Android Relative layout hides my images view

I have a grid view. and I have simple grid adapter with custom view, But that custom view hides image but I can see view in Eclipse graphical layout view. but when I run it, it hides an image

    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>

Please check your error log for custom grid item layout xml , I have check your code with sample it give me output. May be your images has been corrupted . checked your drawable/ic_launcher file or your resources folder replace with another image and try it.

Please share the image what kind of view you want and. As you are using RelativeLayout it will surely hide some views - Layout_rightof,Layout_above by setting these properties you can set the views appropriately

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"
          />

Above contents shows Textview is right of my ImageView .

-Hello try your Imageview Fixed height and width check what happens.

  1. Remove Unnecessary LinearLayout .

  2. Wrap your ImageView by FrameLayout as:

     <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> 

Hope this help!

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM