像这个图像的设计布局是什么用于设计

时间:2016-09-07 12:07:37

标签: android layout

[https://github.com/rinoto/spring-auto-mock

左侧滑动中心值自动检查并在布局中显示相关表格。

1 个答案:

答案 0 :(得分:0)

试试这个

MainActivity.java

public class MainActivity extends AppCompatActivity {
private TextView[] dots;
private LinearLayout dotsLayout;
// Declare Variables
ViewPager viewPager;

String[] CustomerNameList;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    CustomerNameList = new String[]{"xxxxx", "sssss", "aaaaaa", "ffffff", "gggggggg", "jjjjj"};

    dotsLayout = (LinearLayout) findViewById(R.id.layoutDots);

    addBottomDots(0);

    // Locate the ViewPager in viewpager_main.xml
    viewPager = (ViewPager) findViewById(R.id.first_customer_popup_view_pager);
    // Pass results to ViewPagerAdapter Class
    CustomPagerAdapter adapter = new CustomPagerAdapter(this, CustomerNameList);
    // Binds the Adapter to the ViewPager
    viewPager.setAdapter(adapter);
    viewPager.addOnPageChangeListener(viewPagerPageChangeListener);

}

private void addBottomDots(int currentPage) {
    dots = new TextView[CustomerNameList.length];
    int colorsActive = Color.rgb(102, 41, 125);
    int colorsInactive = Color.rgb(217, 217, 217);

    dotsLayout.removeAllViews();
    for (int i = 0; i < dots.length; i++) {
        dots[i] = new TextView(this);
        dots[i].setText(Html.fromHtml("&#8226;"));
        dots[i].setTextSize(100);
        dots[i].setTextColor(colorsInactive);
        dotsLayout.addView(dots[i]);
    }

    if (dots.length > 0)
        dots[currentPage].setTextColor(colorsActive);
}

//  viewpager change listener
ViewPager.OnPageChangeListener viewPagerPageChangeListener = new ViewPager.OnPageChangeListener() {

    @Override
    public void onPageSelected(int position) {
        addBottomDots(position);
    }

    @Override
    public void onPageScrolled(int arg0, float arg1, int arg2) {

    }

    @Override
    public void onPageScrollStateChanged(int arg0) {

    }
};
}

CustomPagerAdapter.java

public class CustomPagerAdapter extends PagerAdapter {

private Context context;
private String[] CustomerNameList;

LayoutInflater inflater;

public CustomPagerAdapter(Context context,String[] CustomerNameList) {
    this.context = context;
    this.CustomerNameList = CustomerNameList;
}

@Override
public int getCount() {
    return CustomerNameList.length;
}

@Override
public boolean isViewFromObject(View view, Object object) {
    return view == ((LinearLayout) object);
}

@Override
public Object instantiateItem(ViewGroup container, int position) {

    // Declare Variables
    TextView AO_investments_list_popup_name;
    TextView AO_investments_list_popup_na;
    ListView all_listView;

    inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View itemView = inflater.inflate(R.layout.adapter_single_page, container, false);

    // Locate the TextViews in viewpager_item.xml
    AO_investments_list_popup_name = (TextView) itemView.findViewById(R.id.display);

    AO_investments_list_popup_name.setText(CustomerNameList[position]);

    ((ViewPager) container).addView(itemView);

    return itemView;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    // Remove viewpager_item.xml from ViewPager
    ((ViewPager) container).removeView((LinearLayout) object);

}
}

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.agthamays.sof_1.MainActivity">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.view.ViewPager
        android:id="@+id/first_customer_popup_view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true" />

    <LinearLayout
        android:id="@+id/layoutDots"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="@color/colorAccent"
        android:gravity="center|center_vertical"
        android:orientation="horizontal">
    </LinearLayout>


</RelativeLayout>


</LinearLayout>

adapter_single_page.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:background="@color/colorPrimaryDark"
android:orientation="horizontal"
android:layout_height="wrap_content">

<TextView
    android:id="@+id/display"
    android:layout_width="wrap_content"
    android:text="xxxx"
    android:textSize="24dp"
    android:paddingLeft="100dp"
    android:textStyle="bold"
    android:textColor="@color/colorAccent"
    android:layout_gravity="center"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />
    </LinearLayout>