标签: android-controls

如何根据星星数改变颜色RatingBar?

如何做到以下几点?

如果RatingBar有1-3颗星 - 红星.如果RatingBar有4颗星 - 黄星.如果RatingBar有5颗星 - 绿色星星.

((RatingBar) layout.findViewById(R.id.ratingBar)).setProgress(Integer.parseInt(surveyBeans.get(section).get(position).getRate()));


<RatingBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/ratingBar" android:stepSize="1" android:clickable="false"
            style="?android:attr/ratingBarStyleSmall" android:layout_gravity="right"
        android:layout_marginRight="15dp" />
Run Code Online (Sandbox Code Playgroud)

编辑:

 @Override
    public View getItemView(int section, int position, View convertView, ViewGroup parent) {
        LinearLayout layout;
        if (convertView == null) {
            LayoutInflater inflator = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            layout = (LinearLayout) inflator.inflate(R.layout.item_survey, null);
        } else {
            layout = (LinearLayout) convertView;
        }
        ((TextView) layout.findViewById(R.id.questionSurvey)).setText(surveyBeans.get(section).get(position).getQuestion());
        RatingBar ratingBar = ((RatingBar) layout.findViewById(R.id.ratingBar));
        ratingBar.setProgress(Integer.parseInt(surveyBeans.get(section).get(position).getRate()));
        LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable();
        stars.getDrawable(2).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
        stars.getDrawable(1).setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
        ((TextView) layout.findViewById(R.id.commentSurvey)).setText(surveyBeans.get(section).get(position).getComment());

        return layout;
    } …
Run Code Online (Sandbox Code Playgroud)

android android-controls

10
推荐指数
1
解决办法
2万
查看次数

如何垂直显示文本或在布局XML文件中旋转TextView?

我想在视图中垂直显示一个字符串,如下所示,有没有办法在布局XML文件中实现它?

在此输入图像描述

android android-controls android-layout

8
推荐指数
1
解决办法
8034
查看次数

调整android datepicker控件的大小

如何将android datepicker控件的初始大小调整为更小或更大.有没有办法重新实现它?

android android-widget android-controls

7
推荐指数
1
解决办法
2万
查看次数

实现类似画廊的滑块控件

找不到如何实现这样的控制,甚至不知道它的名字:

在此输入图像描述

每个1,2和3个元素都是相同的自定义控件(让它们命名为项目).物品应该可以通过手指在两个方向上滑动,并且(通过按照控制下方的点点击也会很棒).重要的是要在屏幕上看到整个单项(不是第1部分和第2部分ListView).

它可以在Android上实现吗?如果是,请说明如何执行此操作并告诉我该控件的名称.

android android-controls android-layout

1
推荐指数
1
解决办法
5657
查看次数