1

所以我基本上是在寻找一个可以横向滚动并锁定到位的自定义 ViewGroup,并在这里找到了一个:https ://github.com/ysamlan/horizo​​ntalpager/tree/master/src/com/github/ysamlan/horizo​​ntalpager

之后,我继续编辑我的 attrs.xml 文件,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="HorizontalPager">
    <attr name="handle" format="reference" />
    <attr name="content" format="reference" />
    <attr name="collapsedHeight" format="dimension" />
</declare-styleable>
</resources>

因此,主 xml 的问题得到了修复(或者 Eclipse 说):

<?xml version="1.0" encoding="utf-8"?>
<!--main.xml-->
<com.vrise.bellarmine.HorizontalPager      xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:cl="http://schemas.android.com/apk/res/com.vrise.bellarmine"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:id="@+id/real_view_switcher">
<LinearLayout 
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffccd0"
>
     <TextView
        android:text="Countries List"
    android:textColor="#b3000d"
    android:gravity="center_vertical|center_horizontal"
    android:textSize="26dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:background="#ffb0b6"
    android:layout_marginBottom="5dip"
    android:typeface="sans"/>
 <RelativeLayout
  android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:background="#570000">
 <TextView android:id="@+id/tv_1"
    android:textColor="#FFFFFF"
    android:gravity="center_vertical|left"
    android:textSize="16dip"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:typeface="serif"
    android:layout_width="70dip"
    android:paddingLeft="20dip"
    android:text="Abbr">
 </TextView>
 <TextView android:id="@+id/tv_2"
    android:textColor="#FFFFFF"
    android:gravity="center_vertical|left"
    android:textSize="16dip"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:typeface="serif"
    android:layout_width="200dip"
    android:layout_toRightOf="@+id/tv_1"
    android:text="Countries">
 </TextView>

</RelativeLayout>
<ListView
android:id="@+id/lv_country"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:cacheColorHint="#00000000">
</ListView>
 </LinearLayout>
  </com.vrise.bellarmine.HorizontalPager>

但是,错误日志仍然给我 eclipse.buildId=M20110909-1335

Error
Thu Feb 16 02:05:50 PST 2012
com.vrise.bellarmine.HorizontalPager failed to instantiate.

java.lang.NullPointerException
at com.vrise.bellarmine.HorizontalPager.init(HorizontalPager.java:131)
at com.vrise.bellarmine.HorizontalPager.<init>(HorizontalPager.java:120)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)

这会是什么原因?我觉得我做的都是对的...

4

0 回答 0