我的代码是:
MainActivity.cpp
我只定义了一个按钮来测试页面指示器,代码很简单。单击按钮,页面指示器将更改圆点
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);
}
});
}
}activity_main.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
谁能帮我..。谢谢
发布于 2012-10-01 17:56:20
我也有同样的问题。我不知道为什么会发生这种情况,但出于某种原因,myPI.getDotDrawable()返回了一个null。
我验证了这些样式确实存在于源代码和jar文件中。
我正在检查它以找出问题所在,尽管在eclipse布局预览窗口中,点确实会显示出来。
解决方案:
在您的活动中,添加以下内容:
setTheme(com.cyrilmottier.android.greendroid.R.style.Theme_GreenDroid_NoTitleBar);在setContentView(...)之前
现在工作起来像个护身符:)
发布于 2012-09-24 12:14:11
请参考this link,如何将android:layout_width="match_parent"更改为android:layout_width="wrap_content"。
发布于 2013-04-28 19:31:43
只需在styles.xml中的AppThem中添加以下项目:
<style name="AppTheme" parent="AppBaseTheme">
<item name="gdPageIndicatorStyle">@style/GreenDroid.Widget.PageIndicator</item>
<!-- Now no need to set Theme_GreenDroid in your activity -->
</style>https://stackoverflow.com/questions/12558384
复制相似问题