1

我的代码是:

主活动.cpp

我只是定义了一个按钮来测试 pageindicator,代码很简单。单击按钮和页面指示器更改点

package com.example.androidlab;

import greendroid.widget.PageIndicator;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
    int i = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final Button btn = (Button) findViewById(R.id.btn);
        final PageIndicator pi = (PageIndicator) findViewById(R.id.pi);
        pi.setDotCount(5);
        pi.setActiveDot(0);
        btn.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                pi.setActiveDot((++i) % 5);
            }
        });
    }
}

活动主.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <greendroid.widget.PageIndicator
        android:id="@+id/pi"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </greendroid.widget.PageIndicator>

</LinearLayout>

我使用 android 2.3.1 sdk

谁能帮助我...谢谢

4

3 回答 3

2

我有同样的问题。我不知道为什么会这样,但由于某种原因myPI.getDotDrawable()正在返回一个null.

我验证了样式确实存在于源代码和 jar 文件中。

我正在检查它以找出问题所在,尽管在 Eclipse 布局预览窗口中,点确实出现了。

解决方案:

在您的活动中,添加以下内容:

setTheme(com.cyrilmottier.android.greendroid.R.style.Theme_GreenDroid_NoTitleBar);

setContentView(...)

现在像魅力一样工作:)

于 2012-10-01T09:56:20.203 回答
0

只需将此项添加到您的 AppThem 中的 styles.xml 中:

<style name="AppTheme" parent="AppBaseTheme">
    <item name="gdPageIndicatorStyle">@style/GreenDroid.Widget.PageIndicator</item>
     <!-- Now no need to set Theme_GreenDroid in your activity  -->
</style>
于 2013-04-28T11:31:42.900 回答
0

参考这个链接android:layout_width="match_parent" 换成android:layout_width="wrap_content" .

于 2012-09-24T04:14:11.277 回答