Java Code Examples for android.widget.ScrollView#addView()

The following examples show how to use android.widget.ScrollView#addView() . 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: ActivityUtils.java    From memetastic with GNU General Public License v3.0 6 votes vote down vote up
public void showDialogWithHtmlTextView(@StringRes int resTitleId, String text, boolean isHtml, DialogInterface.OnDismissListener dismissedListener) {
    ScrollView scroll = new ScrollView(_context);
    AppCompatTextView textView = new AppCompatTextView(_context);
    int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, _context.getResources().getDisplayMetrics());

    scroll.setPadding(padding, 0, padding, 0);
    scroll.addView(textView);
    textView.setMovementMethod(new LinkMovementMethod());
    textView.setText(isHtml ? new SpannableString(Html.fromHtml(text)) : text);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);

    AlertDialog.Builder dialog = new AlertDialog.Builder(_context)
            .setPositiveButton(android.R.string.ok, null).setOnDismissListener(dismissedListener)
            .setView(scroll);
    if (resTitleId != 0) {
        dialog.setTitle(resTitleId);
    }
    dialogFullWidth(dialog.show(), true, false);
}
 
Example 2
Source File: ChangelogActivity.java    From RedReader with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {

	PrefsUtility.applySettingsTheme(this);

	super.onCreate(savedInstanceState);

	getSupportActionBarOrThrow().setTitle(R.string.title_changelog);
	getSupportActionBarOrThrow().setHomeButtonEnabled(true);
	getSupportActionBarOrThrow().setDisplayHomeAsUpEnabled(true);

	final LinearLayout items = new LinearLayout(this);
	items.setOrientation(LinearLayout.VERTICAL);

	ChangelogManager.generateViews(this, items, true);

	final ScrollView sv = new ScrollView(this);
	sv.addView(items);
	setBaseActivityContentView(sv);
}
 
Example 3
Source File: InternalSelectionScroll.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ScrollView sv = new ScrollView(this);
    ViewGroup.LayoutParams svLp = new ScrollView.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

    LinearLayout ll = new LinearLayout(this);
    ll.setLayoutParams(svLp);
    sv.addView(ll);

    InternalSelectionView isv = new InternalSelectionView(this, 10);
    int screenHeight = getWindowManager().getDefaultDisplay().getHeight();
    LinearLayout.LayoutParams llLp = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            2 * screenHeight);  // 2x screen height to ensure scrolling
    isv.setLayoutParams(llLp);
    ll.addView(isv);
    
    setContentView(sv);
}
 
Example 4
Source File: LogFragment.java    From android-DisplayingBitmaps with Apache License 2.0 5 votes vote down vote up
public View inflateViews() {
    mScrollView = new ScrollView(getActivity());
    ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    mScrollView.setLayoutParams(scrollParams);

    mLogView = new LogView(getActivity());
    ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
    logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    mLogView.setLayoutParams(logParams);
    mLogView.setClickable(true);
    mLogView.setFocusable(true);
    mLogView.setTypeface(Typeface.MONOSPACE);

    // Want to set padding as 16 dips, setPadding takes pixels.  Hooray math!
    int paddingDips = 16;
    double scale = getResources().getDisplayMetrics().density;
    int paddingPixels = (int) ((paddingDips * (scale)) + .5);
    mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
    mLogView.setCompoundDrawablePadding(paddingPixels);

    mLogView.setGravity(Gravity.BOTTOM);
    mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);

    mScrollView.addView(mLogView);
    return mScrollView;
}
 
Example 5
Source File: LogFragment.java    From android-BasicSyncAdapter with Apache License 2.0 5 votes vote down vote up
public View inflateViews() {
    mScrollView = new ScrollView(getActivity());
    ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    mScrollView.setLayoutParams(scrollParams);

    mLogView = new LogView(getActivity());
    ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
    logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    mLogView.setLayoutParams(logParams);
    mLogView.setClickable(true);
    mLogView.setFocusable(true);
    mLogView.setTypeface(Typeface.MONOSPACE);

    // Want to set padding as 16 dips, setPadding takes pixels.  Hooray math!
    int paddingDips = 16;
    double scale = getResources().getDisplayMetrics().density;
    int paddingPixels = (int) ((paddingDips * (scale)) + .5);
    mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
    mLogView.setCompoundDrawablePadding(paddingPixels);

    mLogView.setGravity(Gravity.BOTTOM);
    mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);

    mScrollView.addView(mLogView);
    return mScrollView;
}
 
Example 6
Source File: LogFragment.java    From user-interface-samples with Apache License 2.0 5 votes vote down vote up
public View inflateViews() {
    mScrollView = new ScrollView(getActivity());
    ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    mScrollView.setLayoutParams(scrollParams);

    mLogView = new LogView(getActivity());
    ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
    logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    mLogView.setLayoutParams(logParams);
    mLogView.setClickable(true);
    mLogView.setFocusable(true);
    mLogView.setTypeface(Typeface.MONOSPACE);

    // Want to set padding as 16 dips, setPadding takes pixels.  Hooray math!
    int paddingDips = 16;
    double scale = getResources().getDisplayMetrics().density;
    int paddingPixels = (int) ((paddingDips * (scale)) + .5);
    mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
    mLogView.setCompoundDrawablePadding(paddingPixels);

    mLogView.setGravity(Gravity.BOTTOM);
    mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);

    mScrollView.addView(mLogView);
    return mScrollView;
}
 
Example 7
Source File: LogFragment.java    From android-play-safetynet with Apache License 2.0 5 votes vote down vote up
public View inflateViews() {
    mScrollView = new ScrollView(getActivity());
    ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    mScrollView.setLayoutParams(scrollParams);

    mLogView = new LogView(getActivity());
    ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
    logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    mLogView.setLayoutParams(logParams);
    mLogView.setClickable(true);
    mLogView.setFocusable(true);
    mLogView.setTypeface(Typeface.MONOSPACE);

    // Want to set padding as 16 dips, setPadding takes pixels.  Hooray math!
    int paddingDips = 16;
    double scale = getResources().getDisplayMetrics().density;
    int paddingPixels = (int) ((paddingDips * (scale)) + .5);
    mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
    mLogView.setCompoundDrawablePadding(paddingPixels);

    mLogView.setGravity(Gravity.BOTTOM);
    mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);

    mScrollView.addView(mLogView);
    return mScrollView;
}
 
Example 8
Source File: LogFragment.java    From android-SwipeRefreshLayoutBasic with Apache License 2.0 5 votes vote down vote up
public View inflateViews() {
    mScrollView = new ScrollView(getActivity());
    ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    mScrollView.setLayoutParams(scrollParams);

    mLogView = new LogView(getActivity());
    ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
    logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    mLogView.setLayoutParams(logParams);
    mLogView.setClickable(true);
    mLogView.setFocusable(true);
    mLogView.setTypeface(Typeface.MONOSPACE);

    // Want to set padding as 16 dips, setPadding takes pixels.  Hooray math!
    int paddingDips = 16;
    double scale = getResources().getDisplayMetrics().density;
    int paddingPixels = (int) ((paddingDips * (scale)) + .5);
    mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
    mLogView.setCompoundDrawablePadding(paddingPixels);

    mLogView.setGravity(Gravity.BOTTOM);
    mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);

    mScrollView.addView(mLogView);
    return mScrollView;
}
 
Example 9
Source File: CrashInfoWindow.java    From NetCloud_android with GNU General Public License v2.0 5 votes vote down vote up
private void initView(Context context){

        mTitleBar = new LinearLayout(context);
        mTitleBar.setGravity(Gravity.CENTER_VERTICAL);
        mTitleBar.setMinimumHeight((int) ResTools.getDimen(R.dimen.title_bar_height));
        mTitleBar.setOrientation(LinearLayout.HORIZONTAL);
        mTitleBar.setGravity(Gravity.LEFT|Gravity.CENTER_VERTICAL);
        mTitleBar.setBackgroundResource(R.color.black);

        int textSize = (int)ResTools.getDimen(R.dimen.textsize1);
        mTitle = new TextView(context);
        mTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        mTitle.setSingleLine();
        mTitle.setTextColor(ResTools.getColor(R.color.background));
        mTitle.setText(R.string.tombstones);
        mTitle.setEllipsize(TextUtils.TruncateAt.START);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        lp.leftMargin = (int)ResTools.getDimen(R.dimen.hor_padding);
        mTitleBar.addView(mTitle,lp);

        mScrollView = new ScrollView(context);
        mScrollView.setBackgroundColor(Color.TRANSPARENT);
        mCrashInfo = new TextView(context);
        mCrashInfo.setTextColor(ResTools.getColor(R.color.text));
        mCrashInfo.setTextSize(TypedValue.COMPLEX_UNIT_PX, (int)ResTools.getDimen(R.dimen.textsize3));
        mScrollView.addView(mCrashInfo, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

        mContentView = new LinearLayout(context);
        mContentView.setBackgroundColor(Color.TRANSPARENT);
        mContentView.setOrientation(LinearLayout.VERTICAL);
        mContentView.addView(mTitleBar);
        mContentView.addView(mScrollView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    }
 
Example 10
Source File: LogFragment.java    From animation-samples with Apache License 2.0 5 votes vote down vote up
public View inflateViews() {
    mScrollView = new ScrollView(getActivity());
    ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    mScrollView.setLayoutParams(scrollParams);

    mLogView = new LogView(getActivity());
    ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
    logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    mLogView.setLayoutParams(logParams);
    mLogView.setClickable(true);
    mLogView.setFocusable(true);
    mLogView.setTypeface(Typeface.MONOSPACE);

    // Want to set padding as 16 dips, setPadding takes pixels.  Hooray math!
    int paddingDips = 16;
    double scale = getResources().getDisplayMetrics().density;
    int paddingPixels = (int) ((paddingDips * (scale)) + .5);
    mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
    mLogView.setCompoundDrawablePadding(paddingPixels);

    mLogView.setGravity(Gravity.BOTTOM);
    mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);

    mScrollView.addView(mLogView);
    return mScrollView;
}
 
Example 11
Source File: LogFragment.java    From ExamplesAndroid with Apache License 2.0 5 votes vote down vote up
public View inflateViews() {
    mScrollView = new ScrollView(getActivity());
    ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    mScrollView.setLayoutParams(scrollParams);

    mLogView = new LogView(getActivity());
    ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
    logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    mLogView.setLayoutParams(logParams);
    mLogView.setClickable(true);
    mLogView.setFocusable(true);
    mLogView.setTypeface(Typeface.MONOSPACE);

    // Want to set padding as 16 dips, setPadding takes pixels.  Hooray math!
    int paddingDips = 16;
    double scale = getResources().getDisplayMetrics().density;
    int paddingPixels = (int) ((paddingDips * (scale)) + .5);
    mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
    mLogView.setCompoundDrawablePadding(paddingPixels);

    mLogView.setGravity(Gravity.BOTTOM);
    mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);

    mScrollView.addView(mLogView);
    return mScrollView;
}
 
Example 12
Source File: LogFragment.java    From android-BorderlessButtons with Apache License 2.0 5 votes vote down vote up
public View inflateViews() {
    mScrollView = new ScrollView(getActivity());
    ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    mScrollView.setLayoutParams(scrollParams);

    mLogView = new LogView(getActivity());
    ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
    logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    mLogView.setLayoutParams(logParams);
    mLogView.setClickable(true);
    mLogView.setFocusable(true);
    mLogView.setTypeface(Typeface.MONOSPACE);

    // Want to set padding as 16 dips, setPadding takes pixels.  Hooray math!
    int paddingDips = 16;
    double scale = getResources().getDisplayMetrics().density;
    int paddingPixels = (int) ((paddingDips * (scale)) + .5);
    mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
    mLogView.setCompoundDrawablePadding(paddingPixels);

    mLogView.setGravity(Gravity.BOTTOM);
    mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);

    mScrollView.addView(mLogView);
    return mScrollView;
}
 
Example 13
Source File: LogFragment.java    From user-interface-samples with Apache License 2.0 5 votes vote down vote up
public View inflateViews() {
    mScrollView = new ScrollView(getActivity());
    ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    mScrollView.setLayoutParams(scrollParams);

    mLogView = new LogView(getActivity());
    ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
    logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    mLogView.setLayoutParams(logParams);
    mLogView.setClickable(true);
    mLogView.setFocusable(true);
    mLogView.setTypeface(Typeface.MONOSPACE);

    // Want to set padding as 16 dips, setPadding takes pixels.  Hooray math!
    int paddingDips = 16;
    double scale = getResources().getDisplayMetrics().density;
    int paddingPixels = (int) ((paddingDips * (scale)) + .5);
    mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
    mLogView.setCompoundDrawablePadding(paddingPixels);

    mLogView.setGravity(Gravity.BOTTOM);
    mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);

    mScrollView.addView(mLogView);
    return mScrollView;
}
 
Example 14
Source File: LogFragment.java    From android-AppRestrictionSchema with Apache License 2.0 5 votes vote down vote up
public View inflateViews() {
    mScrollView = new ScrollView(getActivity());
    ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    mScrollView.setLayoutParams(scrollParams);

    mLogView = new LogView(getActivity());
    ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
    logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    mLogView.setLayoutParams(logParams);
    mLogView.setClickable(true);
    mLogView.setFocusable(true);
    mLogView.setTypeface(Typeface.MONOSPACE);

    // Want to set padding as 16 dips, setPadding takes pixels.  Hooray math!
    int paddingDips = 16;
    double scale = getResources().getDisplayMetrics().density;
    int paddingPixels = (int) ((paddingDips * (scale)) + .5);
    mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
    mLogView.setCompoundDrawablePadding(paddingPixels);

    mLogView.setGravity(Gravity.BOTTOM);
    mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);

    mScrollView.addView(mLogView);
    return mScrollView;
}
 
Example 15
Source File: TextFragment.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
	Bundle args = getArguments();
	int type = args.getInt(EXTRA_TYPE);
	String content = args.getString(EXTRA_CONTENT);
	switch (type) {
		case TYPE_LICENSES: {
			InputStream input = null;
			try {
				input = getActivity().getAssets().open("licenses.txt");
				ByteArrayOutputStream output = new ByteArrayOutputStream();
				IOUtils.copyStream(input, output);
				content = new String(output.toByteArray()).replaceAll("\r?\n", "<br/>");
			} catch (IOException e) {
				throw new RuntimeException(e);
			} finally {
				IOUtils.close(input);
			}
			break;
		}
	}
	CharSequence text = HtmlParser.spanify(content, new Markup(), null, null);
	new ColorScheme(getActivity()).apply(text);
	float density = ResourceUtils.obtainDensity(this);
	textView = new CommentTextView(getActivity(), null, android.R.attr.textAppearanceLarge);
	int padding = (int) (16f * density);
	textView.setPadding(padding, padding, padding, padding);
	textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
	textView.setText(text);
	ScrollView scrollView = new ScrollView(getActivity());
	scrollView.setId(android.R.id.list);
	FrameLayout frameLayout = new FrameLayout(getActivity());
	frameLayout.setOnClickListener(this);
	scrollView.addView(frameLayout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
	frameLayout.addView(textView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
	return scrollView;
}
 
Example 16
Source File: LogFragment.java    From android-play-awareness with Apache License 2.0 5 votes vote down vote up
public View inflateViews() {
    mScrollView = new ScrollView(getActivity());
    ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    mScrollView.setLayoutParams(scrollParams);

    mLogView = new LogView(getActivity());
    ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
    logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    mLogView.setLayoutParams(logParams);
    mLogView.setClickable(true);
    mLogView.setFocusable(true);
    mLogView.setTypeface(Typeface.MONOSPACE);

    // Want to set padding as 16 dips, setPadding takes pixels.  Hooray math!
    int paddingDips = 16;
    double scale = getResources().getDisplayMetrics().density;
    int paddingPixels = (int) ((paddingDips * (scale)) + .5);
    mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
    mLogView.setCompoundDrawablePadding(paddingPixels);

    mLogView.setGravity(Gravity.BOTTOM);
    mLogView.setTextAppearance(getActivity(),
            android.R.style.TextAppearance_DeviceDefault_Medium);

    mScrollView.addView(mLogView);
    return mScrollView;
}
 
Example 17
Source File: LogFragment.java    From android-ActivityInstrumentation with Apache License 2.0 5 votes vote down vote up
public View inflateViews() {
    mScrollView = new ScrollView(getActivity());
    ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    mScrollView.setLayoutParams(scrollParams);

    mLogView = new LogView(getActivity());
    ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
    logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    mLogView.setLayoutParams(logParams);
    mLogView.setClickable(true);
    mLogView.setFocusable(true);
    mLogView.setTypeface(Typeface.MONOSPACE);

    // Want to set padding as 16 dips, setPadding takes pixels.  Hooray math!
    int paddingDips = 16;
    double scale = getResources().getDisplayMetrics().density;
    int paddingPixels = (int) ((paddingDips * (scale)) + .5);
    mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
    mLogView.setCompoundDrawablePadding(paddingPixels);

    mLogView.setGravity(Gravity.BOTTOM);
    mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);

    mScrollView.addView(mLogView);
    return mScrollView;
}
 
Example 18
Source File: UIActionSheetDialog.java    From Auie with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 构建内容视图 - ANDROID
 * @return 内容视图
 */
private View createContentViewForANDROID(){
	//根布局
	rootLayout = new LinearLayout(context);
	rootLayout.setLayoutParams(getParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
	rootLayout.setOrientation(LinearLayout.VERTICAL);
	rootLayout.setBackgroundColor(Color.parseColor("#55000000"));
	rootLayout.setGravity(Gravity.BOTTOM);
	
	parentLayout = new LinearLayout(context);
	parentLayout.setLayoutParams(getParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
	parentLayout.setOrientation(LinearLayout.VERTICAL);
	parentLayout.setBackgroundColor(backgroundColor);
	
	LinearLayout childLayout = new LinearLayout(context);
	LayoutParams childParams = getParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	childLayout.setLayoutParams(childParams);
	childLayout.setOrientation(LinearLayout.VERTICAL);
	
	//标题
	TextView titleTextView = new TextView(context);
	titleTextView.setLayoutParams(getParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
	titleTextView.setMinHeight(48 * DP);
	titleTextView.setTextSize(12);
	titleTextView.setGravity(Gravity.CENTER);
	titleTextView.setTextColor(titleColor);
	if (title == null) {
		titleTextView.setVisibility(View.GONE);
	}else{
		titleTextView.setVisibility(View.VISIBLE);
		titleTextView.setText(title);
	}
	
	//内容外层布局
	sheetLayout = new ScrollView(context);
	sheetLayout.setLayoutParams(getParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
	sheetLayout.setFadingEdgeLength(0);
	
	//内容内层布局
	contentLayout = new LinearLayout(context);
	contentLayout.setLayoutParams(getParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
	contentLayout.setOrientation(LinearLayout.VERTICAL);
	sheetLayout.addView(contentLayout);
	
	//取消按钮
	final TextView cancelTextView = new TextView(context);
	LayoutParams params = getParams(LayoutParams.MATCH_PARENT, 52 * DP);
	params.setMargins(0, 8 * DP, 0, 0);
	cancelTextView.setLayoutParams(params);
	cancelTextView.setTextColor(cancelColor);
	cancelTextView.setTextSize(16);
	cancelTextView.setGravity(Gravity.CENTER);
	cancelTextView.setText("取消");
	cancelTextView.setBackgroundColor(itemBackgroundColor);
	cancelTextView.setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View arg0) {
			dismiss();
		}
	});
	
	//控件创建结束
	childLayout.addView(titleTextView);
	childLayout.addView(sheetLayout);
	parentLayout.addView(childLayout);
	parentLayout.addView(cancelTextView);
	rootLayout.addView(parentLayout);
	if (typeface != null) {
		titleTextView.setTypeface(typeface);
		cancelTextView.setTypeface(typeface);
	}
	return rootLayout;
}
 
Example 19
Source File: EditPageLand.java    From fingerpoetry-android with Apache License 2.0 4 votes vote down vote up
private void initBody(RelativeLayout rlBody, float ratio) {
	svContent = new ScrollView(activity);
	rlBody.addView(svContent, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

	LinearLayout llContent = new LinearLayout(activity);
	llContent.setOrientation(LinearLayout.HORIZONTAL);
	svContent.addView(llContent, new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

	etContent = new EditText(activity);
	int padding = (int) (DESIGN_LEFT_PADDING * ratio);
	etContent.setPadding(padding, padding, padding, padding);
	etContent.setBackgroundDrawable(null);
	etContent.setTextColor(0xff3b3b3b);
	etContent.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21);
	etContent.setText(sp.getText());
	LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT);
	lp.weight = 1;
	llContent.addView(etContent, lp);
	etContent.addTextChangedListener(this);

	rlThumb = new RelativeLayout(activity);
	rlThumb.setBackgroundColor(0xff313131);
	int	thumbWidth = (int) (DESIGN_THUMB_HEIGHT_L * ratio);
	int	xWidth = (int) (DESIGN_REMOVE_THUMB_HEIGHT_L * ratio);
	lp = new LinearLayout.LayoutParams(thumbWidth, thumbWidth);
	lp.rightMargin = lp.bottomMargin = lp.topMargin = padding;
	llContent.addView(rlThumb, lp);

	aivThumb = new AsyncImageView(activity) {
		public void onImageGot(String url, Bitmap bm) {
			thumb = bm;
			super.onImageGot(url, bm);
		}
	};
	aivThumb.setScaleToCropCenter(true);
	RelativeLayout.LayoutParams rllp = new RelativeLayout.LayoutParams(thumbWidth, thumbWidth);
	rlThumb.addView(aivThumb, rllp);
	aivThumb.setOnClickListener(this);
	initThumb(aivThumb);

	xvRemove = new XView(activity);
	xvRemove.setRatio(ratio);
	rllp = new RelativeLayout.LayoutParams(xWidth, xWidth);
	rllp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
	rllp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
	rlThumb.addView(xvRemove, rllp);
	xvRemove.setOnClickListener(this);
}
 
Example 20
Source File: BootstrapDropDown.java    From Android-Bootstrap with MIT License 4 votes vote down vote up
private ScrollView createDropDownView() {
    final LinearLayout dropdownView = new LinearLayout(getContext());
    ScrollView scrollView = new ScrollView(getContext());
    int clickableChildCounter = 0;

    dropdownView.setOrientation(LinearLayout.VERTICAL);
    int height = (int) (itemHeight * bootstrapSize);
    LayoutParams childParams = new LayoutParams(LayoutParams.MATCH_PARENT, height);

    for (String text : dropdownData) {
        TextView childView = new TextView(getContext());
        childView.setGravity(Gravity.CENTER_VERTICAL);
        childView.setLayoutParams(childParams);

        int padding = (int) (baselineItemLeftPadding * bootstrapSize);
        childView.setPadding(padding, 0, padding, 0);
        childView.setTextSize(baselineDropDownViewFontSize * bootstrapSize);
        childView.setTextColor(ColorUtils.resolveColor(android.R.color.black, getContext()));

        Drawable background = getContext().obtainStyledAttributes(null, new int[]{
                android.R.attr.selectableItemBackground}, 0, 0)
                                        .getDrawable(0);
        ViewUtils.setBackgroundDrawable(childView, background);

        childView.setTextColor(BootstrapDrawableFactory.bootstrapDropDownViewText(getContext()));
        childView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dropdownWindow.dismiss();
                if (onDropDownItemClickListener != null) {
                    onDropDownItemClickListener.onItemClick(dropdownView, v, v.getId());
                }
            }
        });

        if (Pattern.matches(SEARCH_REGEX_HEADER, text)) {
            childView.setText(text.replaceFirst(REPLACE_REGEX_HEADER, ""));
            childView.setTextSize((baselineDropDownViewFontSize - 2F) * bootstrapSize);
            childView.setClickable(false);
            childView.setTextColor(ColorUtils.resolveColor(R.color.bootstrap_gray_light,
                                                           getContext()));
        }
        else if (Pattern.matches(SEARCH_REGEX_SEPARATOR, text)) {
            childView = new DividerView(getContext());
            childView.setClickable(false);
            childView.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 3));
        }
        else if (Pattern.matches(SEARCH_REGEX_DISABLED, text)) {
            childView.setEnabled(false);
            childView.setId(clickableChildCounter++);
            childView.setText(text.replaceFirst(REPLACE_REGEX_DISABLED, ""));
        }
        else {
            childView.setText(text);
            childView.setId(clickableChildCounter++);
        }
        dropdownView.addView(childView);
    }

    dropdownView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
    dropDownViewHeight = dropdownView.getMeasuredHeight();
    dropDownViewWidth = dropdownView.getMeasuredWidth();

    scrollView.setVerticalScrollBarEnabled(false);
    scrollView.setHorizontalScrollBarEnabled(false);
    scrollView.addView(dropdownView);

    cleanData();
    return scrollView;
}