由于我準備制作警報應用程式,我使用了我的網站而不是XML代碼。但是為了進入我的網頁活動的警報活動,我做了一個意圖,在點擊我的小圖片視圖時發揮作用。
這是我的XML代碼,如下:
activity_web.xml 。<?xml version="1.0" encoding="utf-8"? >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"/span>
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"。
tools:context=".WebActivity"/span>>
<WebView。
android:id="@ id/webview"
android:layout_width="match_parent"。
android:layout_height="match_parent"。
android:layout_centerInParent="true"/span>>
</WebView>/span>
<ImageView
android:id="@ id/imageView"
android:layout_width="81dp"。
android:layout_height="75dp"/span>
android:layout_alignParentEnd="true"。
android:layout_alignParentBottom="true"。
tools:srcCompat="@drawable/bell_icon"/span> />
</RelativeLayout>/span>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
但主要問題是,當我在手機上安裝應用程式時,imageview是不可見的。
。它在我的android Studio布局中也是可見的。
現在告訴我應該怎么做才能讓它在最終構建的apk中可見,從而在我的手機中運行。
uj5u.com熱心網友回復:
你使用了錯誤的屬性命名空間,我很驚訝AS預覽工具顯示了這個圖片,它不應該。但是你的ImageView在設備上是存在的,它是可以點擊的(按照你的設定),它只是有透明的內容(錯誤地解決了srcCompatattr,如下所示)。作為測驗,你可以添加android:background="#789810"標簽,ImageView將顯示出可見的背景(仍然沒有影像)
在你的代碼中你有
tools:srcCompat="@drawable/bell_icon"/span>
tools命名空間指向"一些工具",如使用tools:context=".WebActivity"。為設定特定View的自定義屬性,你必須使用(自定義)資源命名空間,這些在你的XML中用xmlns:app="http://schemas.android.com/apk/res-auto"行宣告,因此你應該使用下面一行
app:srcCompat="@drawable/bell_icon"。
btw. 如果你使用srcCompat,你也應該使用AppCompatImageView。它與通常的ImageView一起作業,只是因為AS專案在構建專案到APK/bundle的程序中默認將所有ImageView交換為AppCompatImageView。這個行為可以被改變或禁用,那么你的ImageView將保持沒有任何影像設定。設定影像的正確行是ImageView的默認src屬性,所以:
android:src="@drawable/bell_icon"/span>
android命名空間在這里,因為這個屬性屬于框架("內置"),而不是一些額外的庫和View(AppCompatImageView來自AppCompat或AndroidX庫)
uj5u.com熱心網友回復:
你可以通過使用約束布局來正確地設定它,這里有一段代碼,也許它是可行的!
在這里我在頂部設定了一個ImageView,webview被設定在ImageView的底部。<androidx.constraintlayout.widget.ConstraintLayout。
android:layout_width="match_parent"
android:layout_height="match_parent"/span>>
<ImageView
android:id="@ id/imageView"
android:layout_width="match_parent"。
android:layout_height="180dp"。
android:background="@color/white"
app:layout_constraintTop_toTopOf="parent"。
app:layout_constraintStart_toStartOf="father"/>
<WebView。
android:layout_width="match_parent"/span>
android:layout_height="0dp"。
app:layout_constraintTop_toBottomOf="@ id/imageView"
app:layout_constraintBottom_toBottomOf="father"/>
</androidx.constraintlayout.widget.ConstraintLayout>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/313074.html
標籤:
上一篇:安卓布局中ImageView和TextView之間的空間
下一篇:attr/selectableItemBackgroundBorderless在工具條內的ImageView中不起作用。
