Java Code Examples for android.widget.RelativeLayout#setHorizontalGravity()

The following examples show how to use android.widget.RelativeLayout#setHorizontalGravity() . 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: CustomSwipeBaseAdapter.java    From android-common-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Makes a new view that combines itemView and swipeLeftView to hold the
 * data pointed to by position.
 *
 * @param context  Interface to application's global information
 * @param position The position from which to get the data.
 * @param parent   The View to which the new view is attached to
 * @return
 */
private View newView(Context context, int position, ViewGroup parent) {
    // get a new itemView and init it.
    View itemView = newItemView(context, position, parent);
    if (itemView == null)
        throw new IllegalStateException("the itemView can't be null!");

    // set a tag for the itemMainView which is used in CustomSwipeListView.
    itemView.setTag(CustomSwipeListView.ITEMMAIN_LAYOUT_TAG);
    // itemLayout indicates the outermost layout of the new view.
    RelativeLayout itemLayout = new RelativeLayout(context);
    itemLayout.setLayoutParams(new AbsListView.LayoutParams(
            itemView.getLayoutParams().width, itemView.getLayoutParams().height));
    itemLayout.addView(itemView);

    // get a new swipeLeftView and init it.
    View swipeLeftView = newSwipeLeftView(context, position, parent);
    if (swipeLeftView == null)
        return itemLayout;

    // set a tag for the swipeLeftView which is used in CustomSwipeListView.
    swipeLeftView.setTag(CustomSwipeListView.ITEMSWIPE_LAYOUT_TAG);
    swipeLeftView.setVisibility(View.GONE);

    // itemSwipeLeftLayout indicates the layout of the swipeLeftView.
    RelativeLayout itemSwipeLeftLayout = new RelativeLayout(context);
    itemSwipeLeftLayout.setLayoutParams(new AbsListView.LayoutParams(
            itemView.getLayoutParams().width, itemView.getLayoutParams().height));
    itemSwipeLeftLayout.setHorizontalGravity(Gravity.END);
    itemSwipeLeftLayout.setBackgroundColor(Color.TRANSPARENT);
    itemSwipeLeftLayout.addView(swipeLeftView);
    itemLayout.addView(itemSwipeLeftLayout);
    return itemLayout;
}
 
Example 2
Source File: CustomSwipeBaseAdapter.java    From custom-swipelistview with Apache License 2.0 5 votes vote down vote up
/**
 * Makes a new view that combines itemView and swipeLeftView to hold the
 * data pointed to by position.
 *
 * @param context  Interface to application's global information
 * @param position The position from which to get the data.
 * @param parent   The View to which the new view is attached to
 * @return
 */
private View newView(Context context, int position, ViewGroup parent) {
    // get a new itemView and init it.
    View itemView = newItemView(context, position, parent);
    if (itemView == null)
        throw new IllegalStateException("the itemView can't be null!");

    // set a tag for the itemMainView which is used in CustomSwipeListView.
    itemView.setTag(CustomSwipeListView.ITEMMAIN_LAYOUT_TAG);
    // itemLayout indicates the outermost layout of the new view.
    RelativeLayout itemLayout = new RelativeLayout(context);
    itemLayout.setLayoutParams(new AbsListView.LayoutParams(
            itemView.getLayoutParams().width, itemView.getLayoutParams().height));
    itemLayout.addView(itemView);

    // get a new swipeLeftView and init it.
    View swipeLeftView = newSwipeLeftView(context, position, parent);
    if (swipeLeftView == null)
        return itemLayout;

    // set a tag for the swipeLeftView which is used in CustomSwipeListView.
    swipeLeftView.setTag(CustomSwipeListView.ITEMSWIPE_LAYOUT_TAG);
    swipeLeftView.setVisibility(View.GONE);

    // itemSwipeLeftLayout indicates the layout of the swipeLeftView.
    RelativeLayout itemSwipeLeftLayout = new RelativeLayout(context);
    itemSwipeLeftLayout.setLayoutParams(new AbsListView.LayoutParams(
            itemView.getLayoutParams().width, itemView.getLayoutParams().height));
    itemSwipeLeftLayout.setHorizontalGravity(Gravity.END);
    itemSwipeLeftLayout.setBackgroundColor(mContext.getResources()
            .getColor(android.R.color.transparent));
    itemSwipeLeftLayout.addView(swipeLeftView);
    itemLayout.addView(itemSwipeLeftLayout);
    return itemLayout;
}