Java Code Examples for android.widget.ListView#getWidth()

The following examples show how to use android.widget.ListView#getWidth() . 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: EntitySelectViewSetup.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
public static void setupDivider(Context context, ListView view, boolean useNewDivider) {
    if (useNewDivider) {
        int viewWidth = view.getWidth();
        // sometimes viewWidth is 0, and in this case we default to a reasonable value taken from dimens.xml
        int dividerWidth;
        if (viewWidth == 0) {
            dividerWidth = (int)context.getResources().getDimension(R.dimen.entity_select_divider_left_inset);
        } else {
            dividerWidth = (int)(viewWidth / 6.0);
        }
        dividerWidth += (int)context.getResources().getDimension(R.dimen.row_padding_horizontal);

        LayerDrawable dividerDrawable = (LayerDrawable)context.getResources().getDrawable(R.drawable.divider_case_list_modern);
        dividerDrawable.setLayerInset(0, dividerWidth, 0, 0, 0);

        view.setDivider(dividerDrawable);
        view.setDividerHeight((int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1,
                context.getResources().getDisplayMetrics()));
    } else {
        view.setDivider(null);
    }
}
 
Example 2
Source File: PXOverscrollStyler.java    From pixate-freestyle-android with Apache License 2.0 6 votes vote down vote up
@Override
public void applyStylesWithContext(PXStylerContext stylerContext) {
    // view.setOverScrollMode(ListView.OVER_SCROLL_ALWAYS); // needed?
    OverscrollStyle overscrollStyle = stylerContext.getOverscrollStyle();
    if (overscrollStyle != null) {
        // Get the ListView through the virtual styleable.
        ListView view = (ListView) stylerContext.getStyleable();
        // Apply the overscroll
        setOverscrollDistance(view, overscrollStyle.distance);
        int viewWidth = view.getWidth();
        if (overscrollStyle.header != null) {
            view.setOverscrollHeader(PXDrawableUtil.createDrawable((viewWidth != 0) ? viewWidth
                    : overscrollStyle.distance, overscrollStyle.distance,
                    overscrollStyle.header));
        }
        if (overscrollStyle.footer != null) {
            view.setOverscrollFooter(PXDrawableUtil.createDrawable((viewWidth != 0) ? viewWidth
                    : overscrollStyle.distance, overscrollStyle.distance,
                    overscrollStyle.footer));
        }
    }
    super.applyStylesWithContext(stylerContext);
}
 
Example 3
Source File: ThreadsPage.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
public void apply() {
	ListView listView = getListView();
	listView.removeCallbacks(this);
	listPosition = null;
	positionInfo = null;
	if (listView.getWidth() > 0) {
		run();
	} else {
		listView.post(this);
	}
}
 
Example 4
Source File: ThreadsPage.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
	ListView listView = getListView();
	listView.removeCallbacks(this);
	getAdapter().updateConfiguration(listView.getWidth());
	if (positionInfo != null) {
		int position = getAdapter().getPositionFromInfo(positionInfo);
		if (position != -1 && position != listPosition.position) {
			// Fix list position due to rows count changing
			new ListPosition(position, listPosition.y).apply(listView);
		}
	} else {
		currentWidth = listView.getWidth();
	}
}
 
Example 5
Source File: PXDividerStyler.java    From pixate-freestyle-android with Apache License 2.0 5 votes vote down vote up
@Override
public void applyStylesWithContext(PXStylerContext stylerContext) {
    ListView listView = (ListView) stylerContext.getStyleable();
    // create the divider drawable and set it to the list
    int width = listView.getWidth();
    if (width <= 0) {
        View parent = (View) PXStyleAdapter.getStyleAdapter(listView).getParent(listView);
        if (parent != null) {
            width = parent.getWidth();
        }
    }
    listView.setDivider(PXDrawableUtil.createDrawable(width, listView.getDividerHeight(),
            stylerContext.getDividerFill()));
}