我使用GridLayout的XML佈局是這樣的:不能在網格佈局更改Android ImageView的背景
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:columnCount="8"
app:rowCount="8"
>
<ImageView
android:id="@+id/papan8a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:background="@drawable/white_queen"
app:layout_row="0"
app:layout_column="0"
/>
<TextView
android:id="@+id/bidak8a"
android:background="@drawable/black_rook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Contoh"
app:layout_row="0"
app:layout_column="0"
/>
<ImageView
android:id="@+id/papan8b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:background="@color/kuningDikit"
app:layout_row="0"
app:layout_column="1"
app:layout_columnWeight="0.5"
/>
<TextView
android:id="@+id/bidak8b"
android:background="@drawable/black_rook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Contoh"
app:layout_row="0"
app:layout_column="1"
/>
</android.support.v7.widget.GridLayout>
</LinearLayout>
輸出是這樣的:
的ImageView應該成爲一個黃色背景對於我的textView,但它從未顯示。儘管我把android:background="#FF0000"
imageView永遠不會改變。那麼這裏有什麼問題......?我在網格佈局中錯過了什麼......? 在此先感謝。
您確切的要求是什麼? – Prasad
我想使imageView作爲一個飛機和textview上...這就像一個國際象棋遊戲先生@Prasad ... –
爲了您的要求,您可以只使用imageview與背景和src屬性,也檢查您的imageview圖像的大小,它可能是小於textview圖像大小,因此它隱藏在texiview – Vickyexpert