先看效果
右下角的点~
图片浏览是gallery,右下角是radioGroup 动态添加radioButton
布局 / 这个我在800 480 的差不多,假如是320 240 就改成150dp, 效果显的还行吧
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="180dp" >
<Gallery
android:id="@+id/gallery"
android:layout_width="match_parent"
android:layout_height="180dp"
android:background="@drawable/showbigpic_bg" />
<RadioGroup
android:id="@+id/radiogroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="5dp"
android:orientation="horizontal" >
</RadioGroup>
</RelativeLayout>
下面是单个radioButton的布局
radio.xml
<?xml version="1.0" encoding="utf-8"?>
<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/radio_bg"
android:button="@null"
android:enabled="false"
android:focusable="false" >
</RadioButton>
radio_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/light" android:state_selected="true"></item>
<item android:drawable="@drawable/light" android:state_focused="true"></item>
<item android:drawable="@drawable/light" android:state_checked="true"></item>
<item android:drawable="@drawable/dark1"></item>
</selector>
//list,首先得知道有gallery有几张图片,也就有几个点
addRadioButton(list.size());
mGallery.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
tv_summary.setText(newsList.get(position).getSummary());
mRadioGroup.check(position);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
.
private void addRadioButton(int count) {
for (int i = 0; i < count; i++) {
RadioButton rb = (RadioButton) LayoutInflater.from(this).inflate(R.layout.radio, null);
rb.setId(i);//注意这个setId(i);
mRadioGroup.addView(rb);
//mRadioGroup.check(position);这个方法需要的是一个控件的明确id,!也就是findViewById(resid);的resid,
//position并不是说代表哪个位置!
}
}
效果 使用图片:
showbigpic_bg.9.png
dark1.png
light.png
所有图片均来自网络,若有侵权,请及时告知