小编Val*_*nov的帖子

如何根据星星数改变颜色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万
查看次数

如何在SwipeRefreshLayout中禁用触摸事件?

我用SwipeRefreshLayout谷歌.我有几个问题.

  1. 如何在激活时阻止触摸屏onRefresh()
  2. 更新期间如何在屏幕旋转中心而不是顶部进行?

    swipeLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipe_status_info);
    swipeLayout.setColorSchemeColors(Color.RED, Color.GREEN, Color.BLUE, Color.CYAN);
    swipeLayout.setOnRefreshListener(this);
    
    
    @Override
    public void onRefresh() {
        clearTable(holidayTable);
        clearTable(cityayTable);
        setData();
    }
    
    Run Code Online (Sandbox Code Playgroud)

android android-layout

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

如何制作带图片和文字的按钮?

我需要创建一个带背景的按钮并将其放在图片上.我试图LinearLayout Horizontal在它上面下注,然后放上背景图片和按钮.但它看起来不太好.告诉我怎么做? 在此输入图像描述

android android-button

-2
推荐指数
1
解决办法
112
查看次数