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

The following examples show how to use android.widget.LinearLayout#setDividerDrawable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdapterImpl.java    From AsymmetricGridView with MIT License 6 votes vote down vote up
ViewHolder onCreateViewHolder() {
  if (debugEnabled) {
    Log.d(TAG, "onCreateViewHolder()");
  }

  LinearLayout layout = new LinearLayout(context, null);
  if (debugEnabled) {
    layout.setBackgroundColor(Color.parseColor("#83F27B"));
  }

  layout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
  layout.setDividerDrawable(
      ContextCompat.getDrawable(context, R.drawable.item_divider_horizontal));

  AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(
      AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT);
  layout.setLayoutParams(layoutParams);
  return new ViewHolder(layout);
}
 
Example 2
Source File: AdapterImpl.java    From AsymmetricGridView with MIT License 6 votes vote down vote up
private LinearLayout findOrInitializeChildLayout(LinearLayout parentLayout, int childIndex) {
  LinearLayout childLayout = (LinearLayout) parentLayout.getChildAt(childIndex);

  if (childLayout == null) {
    childLayout = linearLayoutPool.get();
    childLayout.setOrientation(LinearLayout.VERTICAL);

    if (debugEnabled) {
      childLayout.setBackgroundColor(Color.parseColor("#837BF2"));
    }

    childLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
    childLayout.setDividerDrawable(
        ContextCompat.getDrawable(context, R.drawable.item_divider_vertical));

    childLayout.setLayoutParams(new AbsListView.LayoutParams(
        AbsListView.LayoutParams.WRAP_CONTENT,
        AbsListView.LayoutParams.MATCH_PARENT));

    parentLayout.addView(childLayout);
  }

  return childLayout;
}
 
Example 3
Source File: GeneralDialog.java    From pandora with Apache License 2.0 4 votes vote down vote up
private void transform(Window window) {
    try {
        View sysContent = window.findViewById(Window.ID_ANDROID_CONTENT);
        GradientDrawable backgroundDrawable = new GradientDrawable();
        backgroundDrawable.setCornerRadius(ViewKnife.dip2px(10));
        backgroundDrawable.setColor(Color.WHITE);
        ViewCompat.setBackground(sysContent, backgroundDrawable);

        DialogTitle title = window.findViewById(androidx.appcompat.R.id.alertTitle);
        TextView message = window.findViewById(android.R.id.message);
        Button button1 = window.findViewById(android.R.id.button1);
        Button button2 = window.findViewById(android.R.id.button2);
        Button button3 = window.findViewById(android.R.id.button3);
        LinearLayout buttonParent = (LinearLayout) button1.getParent();

        buttonParent.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
        GradientDrawable verticalDrawable = new GradientDrawable();
        verticalDrawable.setColor(0xffE5E5E5);
        verticalDrawable.setSize(ViewKnife.dip2px(.5f), 0);
        buttonParent.setDividerDrawable(verticalDrawable);
        buttonParent.setPadding(0, 0, 0, 0);

        GradientDrawable innerDrawable = new GradientDrawable();
        innerDrawable.setStroke(ViewKnife.dip2px(.5f), 0xffE5E5E5);
        InsetDrawable insetDrawable = new InsetDrawable(innerDrawable,
                ViewKnife.dip2px(-1), 0, ViewKnife.dip2px(-1), ViewKnife.dip2px(-1));
        ViewCompat.setBackground(buttonParent, insetDrawable);

        window.findViewById(androidx.appcompat.R.id.spacer).setVisibility(View.GONE);

        View textSpacerNoButtons = window.findViewById(androidx.appcompat.R.id.textSpacerNoButtons);
        if (textSpacerNoButtons != null) {
            textSpacerNoButtons.setVisibility(View.VISIBLE);
        }
        button1.setTextColor(0xff5B6B91);
        button2.setTextColor(0xff353535);
        button3.setTextColor(0xff353535);
        button1.setPaintFlags(Paint.FAKE_BOLD_TEXT_FLAG);
        button2.setPaintFlags(Paint.FAKE_BOLD_TEXT_FLAG);
        button3.setPaintFlags(Paint.FAKE_BOLD_TEXT_FLAG);
        ((LinearLayout.LayoutParams) button3.getLayoutParams()).weight = 1;
        ((LinearLayout.LayoutParams) button2.getLayoutParams()).weight = 1;
        ((LinearLayout.LayoutParams) button1.getLayoutParams()).weight = 1;

        if (message != null) {
            message.setTextColor(0xff202020);
            if (getArguments().getBoolean(ATTR7, false)) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    message.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
                } else {
                    message.setGravity(Gravity.CENTER_HORIZONTAL);
                }
            }
        }

        title.setTextColor(0xff353535);
        title.setPaintFlags(Paint.FAKE_BOLD_TEXT_FLAG);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            title.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
        } else {
            title.setGravity(Gravity.CENTER_HORIZONTAL);
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
 
Example 4
Source File: Utility11.java    From CSipSimple with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setLinearLayoutDividerDrawable(LinearLayout l, Drawable d) {
    l.setDividerDrawable(d);
    super.setLinearLayoutDividerDrawable(l, d);
}
 
Example 5
Source File: TabLayoutActivity.java    From MaterialDesignDemo with MIT License 4 votes vote down vote up
@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);
        }
    }
 
Example 6
Source File: RoundHelper.java    From RadioRealButton with Apache License 2.0 4 votes vote down vote up
static void makeDividerRound(LinearLayout layout, int dividerColor, int dividerRadius, Integer dividerSize) {
    GradientDrawable gradient = getGradientDrawable(dividerColor, dividerRadius, dividerSize);
    layout.setDividerDrawable(gradient);
}
 
Example 7
Source File: ClickableToast.java    From Dashchan with Apache License 2.0 4 votes vote down vote up
private ClickableToast(Holder holder) {
	this.holder = holder;
	Context context = holder.context;
	float density = ResourceUtils.obtainDensity(context);
	int innerPadding = (int) (8f * density);
	LayoutInflater inflater = LayoutInflater.from(context);
	View toast1 = inflater.inflate(LAYOUT_ID, null);
	View toast2 = inflater.inflate(LAYOUT_ID, null);
	TextView message1 = toast1.findViewById(android.R.id.message);
	TextView message2 = toast2.findViewById(android.R.id.message);
	View backgroundSource = null;
	Drawable backgroundDrawable = toast1.getBackground();
	if (backgroundDrawable == null) {
		backgroundDrawable = message1.getBackground();
		if (backgroundDrawable == null) {
			View messageParent = (View) message1.getParent();
			if (messageParent != null) {
				backgroundDrawable = messageParent.getBackground();
				backgroundSource = messageParent;
			}
		} else {
			backgroundSource = message1;
		}
	} else {
		backgroundSource = toast1;
	}

	StringBuilder builder = new StringBuilder();
	for (int i = 0; i < 100; i++) builder.append('W'); // Make long text
	message1.setText(builder); // Avoid minimum widths
	int measureSize = (int) (context.getResources().getConfiguration().screenWidthDp * density + 0.5f);
	toast1.measure(View.MeasureSpec.makeMeasureSpec(measureSize, View.MeasureSpec.AT_MOST),
			View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
	toast1.layout(0, 0, toast1.getMeasuredWidth(), toast1.getMeasuredHeight());
	Rect backgroundSourceTotalPadding = getViewTotalPadding(toast1, backgroundSource);
	Rect messageTotalPadding = getViewTotalPadding(toast1, message1);
	messageTotalPadding.left -= backgroundSourceTotalPadding.left;
	messageTotalPadding.top -= backgroundSourceTotalPadding.top;
	messageTotalPadding.right -= backgroundSourceTotalPadding.right;
	messageTotalPadding.bottom -= backgroundSourceTotalPadding.bottom;
	int horizontalPadding = Math.max(messageTotalPadding.left, messageTotalPadding.right) +
			Math.max(message1.getPaddingLeft(), message1.getPaddingRight());
	int verticalPadding = Math.max(messageTotalPadding.top, messageTotalPadding.bottom) +
			Math.max(message1.getPaddingTop(), message1.getPaddingBottom());

	ViewUtils.removeFromParent(message1);
	ViewUtils.removeFromParent(message2);
	LinearLayout linearLayout = new LinearLayout(context);
	linearLayout.setOrientation(LinearLayout.HORIZONTAL);
	linearLayout.setDividerDrawable(new ToastDividerDrawable(0xccffffff, (int) (density + 0.5f)));
	linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
	linearLayout.setDividerPadding((int) (4f * density));
	linearLayout.setTag(this);
	linearLayout.addView(message1, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
	linearLayout.addView(message2, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
	((LinearLayout.LayoutParams) message1.getLayoutParams()).weight = 1f;
	linearLayout.setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding);

	partialClickDrawable = new PartialClickDrawable(backgroundDrawable);
	message1.setBackground(null);
	message2.setBackground(null);
	linearLayout.setBackground(partialClickDrawable);
	linearLayout.setOnTouchListener(partialClickDrawable);
	message1.setPadding(0, 0, 0, 0);
	message2.setPadding(innerPadding, 0, 0, 0);
	message1.setSingleLine(true);
	message2.setSingleLine(true);
	message1.setEllipsize(TextUtils.TruncateAt.END);
	message2.setEllipsize(TextUtils.TruncateAt.END);
	container = linearLayout;
	message = message1;
	button = message2;

	windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
}
 
Example 8
Source File: IconicTabsView.java    From AndroidIndicators with Apache License 2.0 3 votes vote down vote up
public IconicTabsView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);


    setFillViewport(true);
    setWillNotDraw(false);

    setHorizontalScrollBarEnabled(false);
    setVerticalScrollBarEnabled(false);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    int dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, dm);
    float dp48 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48, dm);

    minTabWidth = (int) dp48;

    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) dp48);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setLayoutParams(params);
    tabsContainer.setDividerDrawable(getResources().getDrawable(R.drawable.andindicators___iconic_tabs_divider));
    tabsContainer.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
    tabsContainer.setDividerPadding(dividerPadding);
    addView(tabsContainer);

}