2012-03-07 52 views
0

我正在构建一个作为大学项目的flashcards应用程序,并且希望水平滚动显示卡片。我为闪存卡设计本身构建了一个xml文件:在活动布局中多次合并/包含xml布局文件的最佳解决方案

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/relativeLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:background="@drawable/whitenote" android:padding="3dp"> 

    <ImageButton 
     android:id="@+id/imageButtonPins" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" android:background="@color/transparent" android:src="@drawable/pinselector"/> 

    <TextView 
     android:id="@+id/textViewWord" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/imageButton1" 
     android:layout_centerHorizontal="true" 
     android:text="Word" android:textColor="@color/black" android:paddingTop="30dp" android:textSize="20dp"/> 

    <TextView 
     android:id="@+id/textViewMeaning" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/textViewWord" 
     android:layout_centerHorizontal="true" 
     android:text="Meaning" android:textColor="@color/black"/> 

</RelativeLayout> 

我也创建了Class文件。

在活动布局中,我还有几个元素,因此在根级别上需要一个线性布局。我已经能够使用和使用布局充气器来显示单个闪卡用于测试目的。

问题
在这两个方面,在和布局吹气我一直无法获得的ImageButton工作。我的问题是如何让按钮工作。

更新:管理让ImageButton正在使用。意识到我必须处理活动中的onclick事件,而不是自定义适配器类。这应该让我获得的话,只要我可以跟踪显示“当前”闪存卡

此外,什么是最好的方式来处理flashcard应用程序的滚动?我目前的计划是使用Horizo​​ntalScrollView并对其进行自定义,因为我需要(a)刷卡使闪卡只能移动到下一个(b)我需要关注“当前”闪存卡,因为我需要来自其子女观点的一些数据(即,该词)。

+0

'ImageButton'不能正常工作吗?它不可见吗?它没有回应吗?什么是错的,你期望会发生什么? – kabuko 2012-03-07 23:09:05

+0

@Kabuko:我已经设法让按钮开始工作了。它没有响应点击事件,我意识到它必须在活动类中处理,而不是在自定义适配器类中处理。 – 2012-03-07 23:20:07

回答

1

你在考虑碎片吗?

您可以在这里获得一些有关ViewPager的帮助。此功能在Android 3.0或更高版本或Android 1.6兼容性软件包中受支持。

http://geekyouup.blogspot.com/2011/07/viewpager-example-from-paug.html

如果你不希望使用的片段,你可以简单地使用画廊。这样,您可以实现水平滚动。 (就像在亚马逊应用程序中)没有复杂的ViewPager。

+0

ViewPager是我已经走了,虽然所有三个建议,我给你正确的答案,因为你链接的例子是非常有用的。谢谢,每个人 – 2012-03-09 22:15:06

1

对于问题的第二部分,请看ViewPager

+0

谢谢,我会立即检查这个 – 2012-03-07 23:20:21

1

A HorizontalScrollViewGallery可能是最直接的实现方法。我不使用Gallery - 但至少知道它存在是件好事。

如果你想有一个更健壮的实现,我同意dcanh121并认为你应该检查出Fragment基于ViewPager。这将允许更多的选择,而不仅仅是一个视图,但可能会根据目标矫枉过正。 A fragment基本上是ActivityView的奇怪后代,但不要在此引用我。

此外,

充气布局是昂贵的,所以尽量只充气XML为View一次,并重新使用该View对象。每次绘制新的flashcard时尽量不要重新填充XML。