我為我的應用制作了自己版本的橫跨螢屏底部的行動欄,并且在該行動欄的按鈕中放置的圖示方面遇到了一個令人困惑的問題。該布局非常簡單。
<LinearLayout
android:id="@ id/navbar"/span>
android:layout_width="match_parent"。
android:layout_height="64dp"/span>
android:layout_alignParentBottom="true"/span>
android:elevation="1dp"/span>
android:gravity="center"/span>
android:background="@color/black_overlay" >
<ImageButton
android:layout_width="wrap_content"/span>
android:layout_height="wrap_content"/span>
android:layout_gravity="center|center"/span>
android:layout_marginStart="8dp"/span>
android:layout_marginEnd="8dp"/span>
android:backgroundTintMode="multiply"/span>
android:backgroundTint="@android:color/transparent"/span>
android:foregroundTint="@color/white"/span>
android:src="@drawable/ic_list_48"/span>
android:contentDescription="地圖按鈕" />
<ImageButton
android:layout_width="wrap_content"/span>
android:layout_height="wrap_content"/span>
android:layout_gravity="center|center"/span>
android:layout_marginStart="8dp"/span>
android:layout_marginEnd="8dp"/span>
android:backgroundTintMode="multiply"/span>
android:backgroundTint="@android:color/transparent"/span>
android:src="@android:drawable/ic_popup_reminder"/span>
android:contentDescription="Notifications Button" />
我遇到的問題是,當使用一個 "系統 "圖示時,比如上面的 "通知按鈕",該圖示會正確縮放以填充ImageButton。但是,當使用一個從系統圖示創建的圖示時,比如上面的 "地圖按鈕",該圖示并沒有像它應該的那樣縮放來填充ImageButton。有什么方法可以讓它這樣做嗎?
uj5u.com熱心網友回復:
嘗試一下
android:scaleType="fitxy"/span>
uj5u.com熱心網友回復:
你的圖示不是為了適應ImageButtons而放大的,而是ImageButtons為了適應圖示而放大的,因為你指定了'wrap_content',所以每個圖示都有一個固有的寬度。你可以在這里看到:
左邊的按鈕有標準的矢量可畫的啟動圖示(寬/高=108dp),右邊的圖示是系統定義的PNG,大小因平臺而異。
你沒有指定你想要的布局方式,但我建議如下:
你沒有指定你想要的布局方式。
<LinearLayout
android:id="@ id/navbar"/span>
android:layout_width="match_parent"。
android:layout_height="64dp"/span>
android:layout_alignParentBottom="true"/span>
android:background="@color/black"/span>
android:elevation="1dp"/span>
android:gravity="center"/span>
tools:context=".MainActivity">
<ImageButton
android:layout_width="0dp"/span>
android:layout_height="match_parent"/span>
android:layout_gravity="center|center"/span>
android:layout_marginStart="8dp"/span>
android:layout_marginEnd="8dp"/span>
android:layout_weight="1"/span>
android:backgroundTint="@android:color/transparent"/span>
android:backgroundTintMode="multiply"/span>
android:contentDescription="地圖按鈕"。
android:foregroundTint="@color/white"/span>
android:src="@drawable/ic_launcher_foreground" />
<ImageButton
android:layout_width="0dp"/span>
android:layout_height="match_parent"/span>
android:layout_gravity="center"/span>
android:layout_marginStart="8dp"/span>
android:layout_marginEnd="8dp"/span>
android:layout_weight="1"/span>
android:backgroundTint="@android:color/transparent"/span>
android:backgroundTintMode="multiply"/span>
android:contentDescription="通知按鈕"。
android:src="@android:drawable/ic_popup_reminder" />
</LinearLayout>
在這里,權重被用來擴展圖示的大小。這導致了以下結果:
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/313060.html
標籤:
下一篇:如何在中間畫一個透明的矩形?


