<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/layoutMain" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > <ImageView android:id="@+id/imageView1" android:layout_width="match_parent" android:layout_height="300px" android:scaleType="fitCenter" android:src="@drawable/a1" /> <RatingBar android:id="@+id/ratingBar1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:max="255" android:numStars="5" android:progress="255" /> </LinearLayout>
package com.moon.hello2; import java.util.Calendar; import android.R.anim; import android.R.integer; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.Button; import android.widget.DatePicker; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.RatingBar; import android.widget.RatingBar.OnRatingBarChangeListener; import android.widget.SeekBar; import android.widget.DatePicker.OnDateChangedListener; import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; import android.widget.TimePicker; import android.widget.TimePicker.OnTimeChangedListener; public class MainActivity extends Activity { private int status = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.activity_main); final ImageView imageView = (ImageView)findViewById(R.id.imageView1); RatingBar ratingBar = (RatingBar)findViewById(R.id.ratingBar1); ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() { @Override public void onRatingChanged(RatingBar arg0, float rating, boolean arg2) { // TODO Auto-generated method stub imageView.setAlpha(rating*5/255); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } }
时间: 2024-10-03 09:44:24