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

The following are Jave code examples for showing how to use requestLayout() 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: androidtools   File: ToastUtils.java   View Source Code Vote up 6 votes
public static void showCenterToast(Context context, String title, @DrawableRes int drawableId, int duration) {
    Toast toast = makeText(context.getApplicationContext(), title, duration);
    toast.setGravity(Gravity.CENTER, 0, 0);
    View view = LayoutInflater.from(context).inflate(R.layout.layout_center_toast, null);
    LinearLayout rlContent = (LinearLayout) view.findViewById(R.id.rl_content);
    TextView content = (TextView) view.findViewById(R.id.tv_content);
    ImageView alertIcon = (ImageView) view.findViewById(R.id.iv_icon);
    if (drawableId != 0) {
        alertIcon.setVisibility(View.VISIBLE);
        alertIcon.setImageResource(drawableId);
    } else {
        alertIcon.setVisibility(View.GONE);
    }
    if (!TextUtils.isEmpty(title)) {
        content.setText(title);
    }
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    int screenWidth = wm.getDefaultDisplay().getWidth();
    int width = (int) (screenWidth / 2f);
    FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) rlContent.getLayoutParams();
    lp.width = width;
    rlContent.setLayoutParams(lp);
    rlContent.requestLayout();
    toast.setView(view);
    toast.show();
}
 
Example 2
Project: androidtools   File: ToastUtils.java   View Source Code Vote up 5 votes
/**
 * Show alert toast view
 *
 * @param context    context
 * @param title      title
 * @param drawableId drawable Id
 * @param duration   duration
 */
public static void showAlertToast(Context context, String title, @DrawableRes int drawableId, int duration) {
    Toast toast = makeText(context.getApplicationContext(), title, duration);
    toast.setGravity(Gravity.CENTER, 0, 0);//the setting position of
    View view = LayoutInflater.from(context).inflate(R.layout.layout_alert_toast, null);
    LinearLayout llContent = (LinearLayout) view.findViewById(R.id.ll_content);
    ImageView alertIcon = (ImageView) view.findViewById(R.id.iv_alert_icon);
    TextView alertTitle = (TextView) view.findViewById(R.id.tv_alert_title);
    if (drawableId != 0) {
        alertIcon.setVisibility(View.VISIBLE);
        alertIcon.setImageResource(drawableId);
    } else {
        alertIcon.setVisibility(View.GONE);
    }
    if (!TextUtils.isEmpty(title)) {
        alertTitle.setText(title);
    }
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    int screenWidth = wm.getDefaultDisplay().getWidth();
    int width = (int) (screenWidth / 1.5f);
    CardView.LayoutParams lp = (CardView.LayoutParams) llContent.getLayoutParams();
    lp.width = width;
    llContent.setLayoutParams(lp);
    llContent.requestLayout();
    toast.setView(view);//Set appearance
    toast.show();
}
 
Example 3
Project: CFAlertDialog   File: CFAlertDialog.java   View Source Code Vote up 5 votes
private void bindCardSubviews() {
    cfDialogScrollView = (ScrollView) dialogCardView.findViewById(R.id.cfdialog_scrollview);
    cfDialogBodyContainer = (LinearLayout) dialogCardView.findViewById(R.id.alert_body_container);
    cfDialogHeaderLinearLayout = (LinearLayout) dialogCardView.findViewById(R.id.alert_header_container);
    cfDialogHeaderLinearLayout.requestLayout();
    cfDialogHeaderLinearLayout.setVisibility(View.GONE);
    dialogTitleTextView = (TextView) dialogCardView.findViewById(R.id.tv_dialog_title);
    iconTitleContainer = (LinearLayout) dialogCardView.findViewById(R.id.icon_title_container);
    cfDialogIconImageView = (ImageView) dialogCardView.findViewById(R.id.cfdialog_icon_imageview);
    dialogMessageTextView = (TextView) dialogCardView.findViewById(R.id.tv_dialog_content_desc);
    buttonContainerLinearLayout = (LinearLayout) dialogCardView.findViewById(R.id.alert_buttons_container);
    cfDialogFooterLinearLayout = (LinearLayout) dialogCardView.findViewById(R.id.alert_footer_container);
    selectableItemsContainer = (LinearLayout) dialogCardView.findViewById(R.id.alert_selection_items_container);
}