安卓学习第23课——ratingBar
progressBar这部分相对而言比较简单
<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"> <ImageView android:id="@+id/image" android:layout_width="match_parent" android:layout_height="240dp" android:src="@drawable/lijiang" /> <RatingBar android:id="@+id/ratingBar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:numStars="5" android:progress="255" android:stepSize="0.5" /> </LinearLayout>
package com.example.ratingbar; import android.app.Activity; import android.os.Bundle; import android.widget.ImageView; import android.widget.RatingBar; import android.widget.RatingBar.OnRatingBarChangeListener; public class MainActivity extends Activity { ImageView image; RatingBar ratingBar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); image=(ImageView) findViewById(R.id.image); ratingBar=(RatingBar) findViewById(R.id.ratingBar); ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener(){ @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { image.setImageAlpha((int) (rating*255/5)); } }); } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。