1.布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="@+id/id_guide_viewpager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:flipInterval="30"
android:persistentDrawingCache="animation" />
<FrameLayout
android:id="@+id/dot_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:layout_marginBottom="16.0dip">
<LinearLayout
android:id="@+id/dot_contain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
</LinearLayout>
<ImageView
android:id="@+id/cur_dot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/dot2_w" />
</FrameLayout>
<ImageView
android:id="@+id/open"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:clickable="true"
android:src="@drawable/ic_open"
android:visibility="gone" />
</RelativeLayout>
讲FrameLayout设置为靠近父控件底部,并水平居中,距离底部距离(bottomMargin)
public void setDotAlignBottom(int px){
View m_obj_view = LayoutInflater.from(context).inflate(R.layout.guide,null);
FrameLayout dot_frame = (FrameLayout) m_obj_view.findViewById(R.id.dot_frame);
/*****因为FrameLayout的父布局是RelativeLayout 所以类型为 RelativeLayout.LayoutParams****/
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(dot_frame.getLayoutParams());
/****设置布局位置****/
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
layoutParams.bottomMargin = px;//or layoutParams.setMargins(0,0,0,px);
dot_frame.setLayoutParams(layoutParams);
}
代码很简单,不多做介绍;