简体   繁体   中英

Imageview not visible at linear layout

I am trying to put an imageview inside my linear layout but it doesn't seem to show for some reason.

Here is my layout xml file -


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/frag_discover_search_image_view"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:paddingStart="16dp"
        android:paddingEnd="16dp"
        android:src="@drawable/ic_icon_search_explore" />


    <com.omadahealth.github.swipyrefreshlayout.library.SwipyRefreshLayout
        android:id="@+id/frag_discover_swipe_refresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:srl_direction="bottom">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/frag_discover_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginStart="8dp"
            android:layout_marginEnd="8dp"
            tools:listitem="@layout/row_video_insta" />
    </com.omadahealth.github.swipyrefreshlayout.library.SwipyRefreshLayout>

    <include layout="@layout/progress_bar" />
</LinearLayout>


and here is my layout at the preview -

在此处输入图像描述

As you can see, at the top left of the view group there is a place for the image but I can't find the reason why it is invisible and un-clickable. Any ideas?

here is the 'ic_icon_search_explore' file -


<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="16dp"
    android:height="16dp"
    android:viewportWidth="16"
    android:viewportHeight="16">
  <path
      android:pathData="M-4,-4h24v24h-24z"
      android:strokeAlpha="0"
      android:strokeWidth="1"
      android:fillColor="#D8D8D8"
      android:fillType="nonZero"
      android:strokeColor="#00000000"
      android:fillAlpha="0"/>
  <path
      android:pathData="M6.8333,6.8333m-5.8333,0a5.8333,5.8333 0,1 1,11.6667 0a5.8333,5.8333 0,1 1,-11.6667 0"
      android:strokeLineJoin="round"
      android:strokeWidth="1.5"
      android:fillColor="#00000000"
      android:strokeColor="#FFFFFF"
      android:fillType="evenOdd"
      android:strokeLineCap="round"/>
  <path
      android:pathData="M15,15L10.9556,10.9556"
      android:strokeLineJoin="round"
      android:strokeWidth="1.5"
      android:fillColor="#00000000"
      android:strokeColor="#FFFFFF"
      android:fillType="evenOdd"
      android:strokeLineCap="round"/>
</vector>


use this drawable. You have to just change the color of an icon.

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="16dp"
        android:height="16dp"
        android:viewportWidth="16"
        android:viewportHeight="16">
    <path
            android:pathData="M-4,-4h24v24h-24z"
            android:strokeAlpha="0"
            android:strokeWidth="1"
            android:fillColor="#000"
            android:fillType="nonZero"
            android:strokeColor="#00000000"
            android:fillAlpha="0"/>
    <path
            android:pathData="M6.8333,6.8333m-5.8333,0a5.8333,5.8333 0,1 1,11.6667 0a5.8333,5.8333 0,1 1,-11.6667 0"
            android:strokeLineJoin="round"
            android:strokeWidth="1.5"
            android:fillColor="#00000000"
            android:strokeColor="#000"
            android:fillType="evenOdd"
            android:strokeLineCap="round"/>
    <path
            android:pathData="M15,15L10.9556,10.9556"
            android:strokeLineJoin="round"
            android:strokeWidth="1.5"
            android:fillColor="#00000000"
            android:strokeColor="#000"
            android:fillType="evenOdd"
            android:strokeLineCap="round"/>
</vector>

Your image is clearly visible but the color of the image is white so it's not showing in layout.

There is no issue with your layout

The issue is in your ic_icon_search_explore icon color

The color of your icon and your layout is white that's why your icon is not showing in layout

Just change the icon color of your ic_icon_search_explore it will work

 <?xml version="1.0" encoding="utf-8"?>
    <vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="16dp"
        android:height="16dp"
        android:viewportWidth="16"
        android:viewportHeight="16">
    <path
            android:pathData="M-4,-4h24v24h-24z"
            android:strokeAlpha="0"
            android:strokeWidth="1"
            android:fillColor="#D8D8D8"
            android:fillType="nonZero"
            android:strokeColor="#00000000"
            android:fillAlpha="0"/>
    <path
            android:pathData="M6.8333,6.8333m-5.8333,0a5.8333,5.8333 0,1 1,11.6667 0a5.8333,5.8333 0,1 1,-11.6667 0"
            android:strokeLineJoin="round"
            android:strokeWidth="1.5"
            android:fillColor="#00000000"
            android:strokeColor="#ff00"
            android:fillType="evenOdd"
            android:strokeLineCap="round"/>
    <path
            android:pathData="M15,15L10.9556,10.9556"
            android:strokeLineJoin="round"
            android:strokeWidth="1.5"
            android:fillColor="#00000000"
            android:strokeColor="#ff00"
            android:fillType="evenOdd"
            android:strokeLineCap="round"/>
</vector>

Not visible because you are set padding inside the ImageView, Paddings are compress image by size. When You set vector image height width then set ImageView Height width as wrap_content

Remove padding:-

 android:paddingStart="16dp" android:paddingEnd="16dp"

Try this ImageView:-

<ImageView
     android:id="@+id/frag_discover_search_image_view"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:src="@drawable/ic_icon_search_explore" />

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