[英]Imageview not visible at linear layout
我試圖將 imageview 放在我的線性布局中,但由於某種原因它似乎沒有顯示。
這是我的布局 xml 文件 -
<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>
這是我在預覽中的布局-
如您所見,在視圖組的左上角有一個放置圖像的位置,但我找不到它不可見且不可點擊的原因。 有任何想法嗎?
這是“ic_icon_search_explore”文件-
<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>
使用這個drawable。 您只需更改圖標的顏色。
<?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>
您的圖像清晰可見,但圖像顏色為白色,因此未在布局中顯示。
您的布局沒有問題
問題在於您的ic_icon_search_explore
圖標顏色
您的圖標和布局的顏色是白色的,這就是您的圖標未顯示在布局中的原因
只需更改ic_icon_search_explore
的圖標顏色即可
<?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>
不可見,因為您在 ImageView 內設置了填充,填充是按大小壓縮圖像。 當您設置矢量圖像高度寬度時,然后將 ImageView 高度寬度設置為wrap_content
刪除填充:-
android:paddingStart="16dp" android:paddingEnd="16dp"
試試這個 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" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.