1.创建xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/s1"
android:id="@+id/iv_iamge"
/>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
android:id="@+id/rg_test"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="3"
android:text="1号佳丽"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="3"
android:text="2号佳丽"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="3"
android:text="3号佳丽"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="3"
android:text="4号佳丽"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="3"
android:text="5号佳丽"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="3"
android:text="6号佳丽"
/>
</RadioGroup>
</LinearLayout>
2.Java类
package com.example.android07_uipv;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.RadioGroup;
/**
* Created by Administrator on 2017/6/7 0007.
*/
public class Test2Activity extends AppCompatActivity {
private ImageView iv_iamge;
private RadioGroup rg_test;
//集合
private int image[]={
R.drawable.s1,
R.drawable.s2,
R.drawable.s3,
R.drawable.s4,
R.drawable.s5,
R.drawable.s6,
};
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test2);
//获取
iv_iamge = (ImageView) findViewById(R.id.iv_iamge);
iv_iamge.setImageResource(image[0]);
rg_test = (RadioGroup) findViewById(R.id.rg_test);
rg_test.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
iv_iamge.setImageResource(image[checkedId-1]);
}
});
}
}
3.实现效果