程序员人生 网站导航

自定义控件---系统控件组合式(案例二)

栏目:综合技术时间:2015-03-26 09:13:33

-----------------------------------------------案例效果-------------------------------------


activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <android.support.v4.view.ViewPager android:id="@+id/viewPager" android:layout_width="match_parent" android:layout_height="200dip" /> <LinearLayout android:gravity="center_horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignBottom="@id/viewPager" android:background="#44000000" android:orientation="vertical" > <TextView android:singleLine="true" android:id="@+id/tv_msg" android:textColor="#ffffff" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="武媚娘传奇" android:textSize="18sp" /> <LinearLayout android:id="@+id/ll_point_group" android:padding="5dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > </LinearLayout> </LinearLayout> </RelativeLayout>
drawable目录下有3个xml文件
point_bg.xml

<?xml version="1.0" encoding="utf⑻"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_enabled="false" android:drawable="@drawable/normal_point"></item> <item android:state_enabled="true" android:drawable="@drawable/focused_point"></item> </selector>
normal_point.xml

<?xml version="1.0" encoding="utf⑻"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" > <size android:width="10dip" android:height="10dip"/> <solid android:color="#55000000"/> </shape>
focused_point.xml

<?xml version="1.0" encoding="utf⑻"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" > <!-- 椭圆 --> <size android:width="10dip" android:height="10dip"/> <solid android:color="#66ffffff"/> </shape>

MainActivity.java

package com.atguigu.myviewpager; import java.util.ArrayList; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; public class MainActivity extends Activity { // viewPager继承viewGroup private ViewPager viewPager; private TextView tv_msg; // 显示当前页的圆点标志布局视图 private LinearLayout ll_point_group; /** * 图片的int数组集合 图片标题集合 图片集合 */ private int[] ids = { R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d, R.drawable.e }; private final String[] imageDescriptions = { "巩俐不低俗,我就不能低俗", "朴树又回来啦!再唱经典老歌引万人大合唱", "揭秘北京电影如何升级", "乐视网TV版大派送", "热血
------分隔线----------------------------
------分隔线----------------------------

最新技术推荐