如何在android中创建“多设置向导栏”?

时间:2016-05-13 03:43:32

标签: android xml android-layout android-fragments android-viewpager

我想设置一个“向导栏”,它将显示如下设置过程的步骤。

enter image description here

所以,如果我在向导的第二阶段,那么将填充2个按钮等。但是按钮填充和我可以手动完成的任何操作(这意味着它不必自动使用向导步骤)但是我我不知道如何实现这样的。

我目前正在ViewPager。有什么想法吗?

mylayout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">

</RelativeLayout>

2 个答案:

答案 0 :(得分:0)

 public void updateIndicators(int position) {
       DisplayMetrics metrics = getResources().getDisplayMetrics();
       int resizeValue = (int) TypedValue.applyDimension(
             TypedValue.COMPLEX_UNIT_DIP, 25, metrics);
       int defaultValue = (int) TypedValue.applyDimension(
             TypedValue.COMPLEX_UNIT_DIP, 15, metrics);
       switch (position) {
       case 0:
          indicator1.getLayoutParams().height = resizeValue;
          indicator1.getLayoutParams().width = resizeValue;
          indicator1.requestLayout();

          indicator2.getLayoutParams().height = defaultValue;
          indicator2.getLayoutParams().width = defaultValue;
          indicator2.requestLayout();

          indicator3.getLayoutParams().height = defaultValue;
          indicator3.getLayoutParams().width = defaultValue;
          indicator3.requestLayout();

          indicator4.getLayoutParams().height = defaultValue;
          indicator4.getLayoutParams().width = defaultValue;
          indicator4.requestLayout();

          break;

       case 1:
          indicator1.getLayoutParams().height = defaultValue;
          indicator1.getLayoutParams().width = defaultValue;
          indicator1.requestLayout();

          indicator2.getLayoutParams().height = resizeValue;
          indicator2.getLayoutParams().width = resizeValue;
          indicator2.requestLayout();

          indicator3.getLayoutParams().height = defaultValue;
          indicator3.getLayoutParams().width = defaultValue;
          indicator3.requestLayout();

          indicator4.getLayoutParams().height = defaultValue;
          indicator4.getLayoutParams().width = defaultValue;
          indicator4.requestLayout();
          break;

       case 2:
          indicator1.getLayoutParams().height = defaultValue;
          indicator1.getLayoutParams().width = defaultValue;
          indicator1.requestLayout();

          indicator2.getLayoutParams().height = defaultValue;
          indicator2.getLayoutParams().width = defaultValue;
          indicator2.requestLayout();

          indicator3.getLayoutParams().height = resizeValue;
          indicator3.getLayoutParams().width = resizeValue;
          indicator3.requestLayout();

          indicator4.getLayoutParams().height = defaultValue;
          indicator4.getLayoutParams().width = defaultValue;
          indicator4.requestLayout();
          break;

       case 3:
          indicator1.getLayoutParams().height = defaultValue;
          indicator1.getLayoutParams().width = defaultValue;
          indicator1.requestLayout();

          indicator2.getLayoutParams().height = defaultValue;
          indicator2.getLayoutParams().width = defaultValue;
          indicator2.requestLayout();

          indicator3.getLayoutParams().height = defaultValue;
          indicator3.getLayoutParams().width = defaultValue;
          indicator3.requestLayout();

          indicator4.getLayoutParams().height = resizeValue;
          indicator4.getLayoutParams().width = resizeValue;
          indicator4.requestLayout();
          break;
       }

    }

答案 1 :(得分:0)

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.androidsrc.viewpagerindicator.MainActivity" >

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <LinearLayout
        android:layout_margin="10dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_gravity="bottom"
        android:orientation="horizontal" >

        <View
            android:id="@+id/indicator1"
            android:layout_width="15dp"
            android:layout_height="15dp"
            android:layout_margin="2dp"
            android:background="@drawable/indicator_bg" />

        <View
            android:id="@+id/indicator2"
            android:layout_width="15dp"
            android:layout_height="15dp"
            android:layout_margin="2dp"
            android:background="@drawable/indicator_bg" />

        <View
            android:id="@+id/indicator3"
            android:layout_width="15dp"
            android:layout_height="15dp"
            android:layout_margin="2dp"
            android:background="@drawable/indicator_bg" />

        <View
            android:id="@+id/indicator4"
            android:layout_width="15dp"
            android:layout_height="15dp"
            android:layout_margin="2dp"
            android:background="@drawable/indicator_bg" />
    </LinearLayout>

</FrameLayout>


Make indicator view in xml like this.