首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法显示greendroid的PageIndicator

无法显示greendroid的PageIndicator
EN

Stack Overflow用户
提问于 2012-09-24 11:07:26
回答 3查看 453关注 0票数 1

我的代码是:

MainActivity.cpp

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

代码语言:javascript
复制
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:

代码语言:javascript
复制
<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

谁能帮我..。谢谢

EN

回答 3

Stack Overflow用户

发布于 2012-10-01 17:56:20

我也有同样的问题。我不知道为什么会发生这种情况,但出于某种原因,myPI.getDotDrawable()返回了一个null

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

我正在检查它以找出问题所在,尽管在eclipse布局预览窗口中,点确实会显示出来。

解决方案:

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

代码语言:javascript
复制
setTheme(com.cyrilmottier.android.greendroid.R.style.Theme_GreenDroid_NoTitleBar);

setContentView(...)之前

现在工作起来像个护身符:)

票数 2
EN

Stack Overflow用户

发布于 2012-09-24 12:14:11

请参考this link,如何将android:layout_width="match_parent"更改为android:layout_width="wrap_content"

票数 0
EN

Stack Overflow用户

发布于 2013-04-28 19:31:43

只需在styles.xml中的AppThem中添加以下项目:

代码语言:javascript
复制
<style name="AppTheme" parent="AppBaseTheme">
    <item name="gdPageIndicatorStyle">@style/GreenDroid.Widget.PageIndicator</item>
     <!-- Now no need to set Theme_GreenDroid in your activity  -->
</style>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12558384

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档