2011-10-04 55 views
0

我創建了包含3個簡單文本視圖的2視圖的圖庫視圖,以呈現我的數據模型中數據的一些 。 在2視圖上調用Invalidate方法時,它就像 視圖失去焦點,在Gallery View中瀏覽時也是如此。圖庫視圖中的視圖在失效或導航時失去「焦點」

「焦點」丟失後,文字變得幾乎不可讀。 (看下面的兩張圖片)

我使用的是Monodroid,但也經常看到Android的例子。

對我的相冊查看代碼:對於這兩種觀點我投入圖庫視圖

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <Gallery 
    android:id="@+id/locationGallery" 
    android:layout_height="match_parent" 
    android:layout_width="fill_parent"> 

    </Gallery> 
</LinearLayout> 

代碼:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:gravity="top" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:padding="3sp" 
    android:id="@+id/locationGalleryItem" 
    > 

    <TextView 
    android:id="@+id/text1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
     android:padding="10dp" 
    android:textSize="16sp" 
    /> 
    <TextView 
    android:id="@+id/text2" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/text1" 
     android:padding="10dp" 
    android:textSize="16sp" 
    /> 
    <TextView 
    android:id="@+id/text3" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/text2" 
     android:padding="10dp" 
    android:textSize="16sp" 
    /> 

</LinearLayout> 

enter image description hereenter image description here

回答

2

我通過在Gallery View上爲ItemSelected屬性創建一個EventHandler來解決了這個問題。這個EventHandler跟蹤圖庫視圖的當前位置。然後調用Gallery View上的SetSelection方法到當前位置。這給出了預期的結果。

代碼:

locationGallery.ItemSelected += new EventHandler<ItemEventArgs>(locationGallery_ItemSelected); 

void locationGallery_ItemSelected(object sender, ItemEventArgs e) 
{ 
    var send = sender as Gallery; 
    send.SetSelection(e.Position); 
} 
+0

使用這是有點bug,當滾動它有點波濤洶涌,有時捕捉到其中一個子視圖。去尋找另一個解決方案。 我在研究圖庫視圖,它似乎沒有默認的焦點功能,所以這可能是爲什麼unselectedAlpha被完全忽略。 – Cheesebaron

+0

所以我最終做出了一個可以在這裏找到的水平分頁器的端口:https://github.com/Cheesebaron/MonoDroid.Horizo​​ntalPager – Cheesebaron

0

我想解決的最簡單方法它會將以下內容添加到您的圖庫中(除非您當然需要):

android:unselectedAlpha="1.0" 
+0

似乎並沒有任何區別。 – Cheesebaron

+0

默認情況下,圖庫視圖會在未選中時顯示兒童略顯透明。上面的代碼將刪除該透明度。 –

+0

由於某種原因,透明度一直留在所有的孩子。雖然我認爲我找到了解決辦法。在發佈之前,我會試着弄清楚它是否真的起作用。 – Cheesebaron