我有兩個Buttons
嵌套在LinearLayout
。這兩個Buttons
之間是兩個TextViews
。在Xml
中,我已將前景設置爲這些Buttons
中的每一個的圖像。如何使按鈕在API 23下工作的前景屬性?
它運行良好,在我的設備上Api 23
。但在Api 23
以下的其他設備上,前景圖像不會顯示,而是會導致默認的白色純色。有沒有什麼辦法讓這些圖像在Api 23
以下使用前景顯示?
我們嘗試過FrameLayout
,但它沒有做到我們希望它做的事情。 ImageButtons
是解決此問題的更好方法嗎?
我們的應用程序的核心功能之一是,每當用戶點擊一個Button
,大小增加,圖像相應地延伸。這是在代碼中動態完成的。如果我要使用ImageButtons
,則需要每次設置高度和寬度的佈局參數,而不是設置高度的一行代碼。
任何提示將不勝感激!
編輯:代碼我一起工作 -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="11"
android:background="@android:color/black">
<Button
android:layout_weight="5"
android:id="@+id/firstP"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:foreground="@drawable/icebutton"
android:scaleX="1"
android:scaleY="1"/>
<TextView
android:layout_weight="0.5"
android:id="@+id/firstPlayer"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:rotation="180"
android:textColor="@android:color/white"
android:background="@android:color/transparent"/>
<TextView
android:layout_weight="0.5"
android:id="@+id/secondPlayer"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:background="@android:color/transparent"/>
<Button
android:layout_weight="5"
android:id="@+id/secondP"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:foreground="@drawable/firebutton"
android:scaleX="1"
android:scaleY="1"/>
</LinearLayout>
請問您可以向我們展示您的代碼! –
我已經添加了我正在使用的代碼。我目前正試圖實現'ImageButtons' @Micho感謝您的編輯。我將確保我將來的格式正確。 – Kumar