Java Code Examples for android.widget.LinearLayout.setDividerDrawable()

The following are Jave code examples for showing how to use setDividerDrawable() of the android.widget.LinearLayout class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: MVP-Practice-Project-Template   File: MultiTypeFragment.java   View Source Code Vote up 6 votes
@Override
protected void showBody() {
    super.showBody();

    viewPagerData.addAll(bindFragment());
    titleData.addAll(bindTitleValue());

    multiTypeAdapter = new MultiTypeAdapter(getChildFragmentManager(), viewPagerData);
    mViewPager.setOffscreenPageLimit(builder.getScreenPageLimit());
    mViewPager.setAdapter(multiTypeAdapter);

    commonNavigator.setAdapter(navigatorAdapter);
    commonNavigator.setAdjustMode(builder.isAdjustMode());
    magicIndicator.setNavigator(commonNavigator);

    LinearLayout titleContainer = commonNavigator.getTitleContainer();
    titleContainer.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
    titleContainer.setDividerDrawable(new ColorDrawable() {
        @Override
        public int getIntrinsicWidth() {
            return UIUtil.dip2px(mContext, builder.getIntrinsicWidth());
        }
    });
    ViewPagerHelper.bind(magicIndicator, mViewPager);
}
 
Example 2
Project: RLibrary   File: TabLayoutUtil.java   View Source Code Vote up 5 votes
public static void setCommonTabDivider(CommonTabLayout tabLayout, @ColorInt int color, int showDividers, int padding) {
    LinearLayout linearLayout = (LinearLayout) tabLayout.getChildAt(0);
    linearLayout.setDividerPadding(padding);
    RectShape rectShape = new RectShape();
    float density = tabLayout.getResources().getDisplayMetrics().density;
    ShapeDrawable shapeDrawable = new ShapeDrawable(rectShape);
    shapeDrawable.setIntrinsicWidth((int) density);
    shapeDrawable.setIntrinsicHeight((int) density);
    shapeDrawable.getPaint().setColor(color);
    shapeDrawable.getPaint().setStyle(Paint.Style.STROKE);
    linearLayout.setDividerDrawable(shapeDrawable);
    linearLayout.setShowDividers(showDividers);
}
 
Example 3
Project: CSipSimple   File: Utility11.java   View Source Code Vote up 4 votes
@Override
public void setLinearLayoutDividerDrawable(LinearLayout l, Drawable d) {
    l.setDividerDrawable(d);
    super.setLinearLayoutDividerDrawable(l, d);
}
 
Example 4
Project: MaterialDesignDemo   File: TabLayoutActivity.java   View Source Code Vote up 4 votes
@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tab_layout);
        mTabLayout = (TabLayout) findViewById(R.id.tabLayout);

        // 手动创建Tab
//        for (int i = 0; i < title.length; i++) {
//            TabLayout.Tab tab = mTabLayout.newTab();
//            tab.setText(title[i]);
////            tab.setIcon(R.mipmap.ic_launcher);//icon会显示在文字上面
//            mTabLayout.addTab(tab);
//        }

        // TabLayout与ViewPager结合使用
        mViewPager = (ViewPager) findViewById(R.id.viewPager);
        MyViewPagerAdapter adapter = new MyViewPagerAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(adapter);
//        // 适配器必须重写getPageTitle()方法
//        mTabLayout.setTabsFromPagerAdapter(adapter);
//        // 监听TabLayout的标签选择,当标签选中时ViewPager切换
//        mTabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
//        // 监听ViewPager的页面切换,当页面切换时TabLayout的标签跟着切换
//        mViewPager.setOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
        // 关联TabLayout与ViewPager,且适配器必须重写getPageTitle()方法
        mTabLayout.setupWithViewPager(mViewPager);


        mLinearLayout = (LinearLayout) mTabLayout.getChildAt(0);
        // 在所有子控件的中间显示分割线(还可能只显示顶部、尾部和不显示分割线)
        mLinearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
        // 设置分割线的距离本身(LinearLayout)的内间距
        mLinearLayout.setDividerPadding(50);
        // 设置分割线的样式
        mLinearLayout.setDividerDrawable(ContextCompat.getDrawable(this, R.drawable.divider_vertical));
        mLinearLayout.setBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));


        // 为TabLayout设置不同状态下的字体大小(并不能成功)
//        for (int i = 0; i < mTabLayout.getTabCount(); i++) {
//            ((TextView) ((LinearLayout) mLinearLayout.getChildAt(i)).getChildAt(1)).setTextSize(10);
////            ((TextView) ((LinearLayout) ((LinearLayout) mTabLayout.getChildAt(0)).getChildAt(i)).getChildAt(0)).setTextSize(12);
//        }
//        ((TextView) ((LinearLayout) mLinearLayout.getChildAt(mTabLayout.getSelectedTabPosition())).getChildAt(1)).setTextSize(30);
//
//        mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
//            @Override
//            public void onTabSelected(TabLayout.Tab tab) {
//                ((TextView) ((LinearLayout) mLinearLayout.getChildAt(tab.getPosition())).getChildAt(1)).setTextSize(30);
//            }
//
//            @Override
//            public void onTabUnselected(TabLayout.Tab tab) {
//                ((TextView) ((LinearLayout) mLinearLayout.getChildAt(tab.getPosition())).getChildAt(1)).setTextSize(10);
//            }
//
//            @Override
//            public void onTabReselected(TabLayout.Tab tab) {
//
//            }
//        });


        // 自定义指示器(Indicator)的“长度”的两种方法
        // 方法一:反射
//        setIndicator(mTabLayout,10,10);
        // 方法二:查找子控件
        int left = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, Resources.getSystem().getDisplayMetrics());
        int right = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, Resources.getSystem().getDisplayMetrics());
        for (int i = 0; i < mLinearLayout.getChildCount(); i++) {
            View tabView = mLinearLayout.getChildAt(0);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1);
            params.leftMargin = left;
            params.rightMargin = right;
            tabView.setLayoutParams(params);
        }
    }