类似网易新闻客户端首页的图片浏览,右下角显示当前第几个图片

  先看效果

 


 右下角的点~

  图片浏览是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


所有图片均来自网络,若有侵权,请及时告知





  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值