Android “画廊视图中的视图丢失”;焦点“;当无效或处于导航状态时

Android “画廊视图中的视图丢失”;焦点“;当无效或处于导航状态时,android,android-layout,xamarin.android,Android,Android Layout,Xamarin.android,我创建了一个包含2个视图和3个简单文本视图的图库视图,以展示一些 我的数据模型中的数据。 在两个视图上调用Invalidate方法时,它与 视图失去焦点,在“库”视图中导航时也是如此 失去“焦点”后,文本几乎无法阅读。(见下图) 我使用的是Monodroid,但也很欣赏常规的Android示例 “我的多媒体资料”视图的代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://sc

我创建了一个包含2个视图和3个简单文本视图的图库视图,以展示一些 我的数据模型中的数据。 在两个视图上调用Invalidate方法时,它与 视图失去焦点,在“库”视图中导航时也是如此

失去“焦点”后,文本几乎无法阅读。(见下图)

我使用的是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>

我放入Gallery视图的两个视图的代码:

<?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>


我想解决这个问题最简单的方法是在你的图库中添加以下内容(当然,除非你需要):


我通过在Gallery视图上为ItemSelected属性生成EventHandler修复了该问题。此EventHandler跟踪库视图的当前位置。然后调用Gallery视图上的方法SetSelection到当前位置。这就得到了期望的结果

代码:

locationGallery.ItemSelected+=新事件处理程序(locationGallery\u ItemSelected);
void locationGallery\u ItemSelected(对象发送方,ItemEventArgs e)
{
var send=发送方作为库;
发送。选择(如位置);
}

这似乎没有任何区别。默认情况下,当未选中子对象时,Gallery视图将显示稍微透明的子对象。上面的代码将删除该透明度。由于某些原因,透明度将保留在所有子项上。虽然我想我已经找到了解决办法。在发布之前,我会试着把它弄得乱七八糟,以测试它是否真的有效。使用它有点麻烦,滚动它时会有点颠簸,有时会捕捉到一个子视图。我们将寻找另一个解决方案。我在研究Gallery View,它似乎没有默认的焦点功能,所以这可能是完全忽略unselectedAlpha的原因。因此,我实际上制作了一个水平寻呼机端口,可以在这里找到: