TextView setGravity - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for TextView setGravity method.

This code example shows how to use the following methods:setLayoutParams, setGravity, setText
         * number. 
         */ 
        @Override 
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            TextView tv = new TextView(getActivity());
            tv.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT,
                    MATCH_PARENT));
            tv.setText("Fragment #" + mNum);
            tv.setGravity(CENTER);
            return tv;
        } 
 
    } 
} 
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setId, setVisibility, setGravity, setPadding, setText
This code example shows how to use the following methods:setLayoutParams, setCompoundDrawablesWithIntrinsicBounds, setGravity, setPadding, setText
			} catch (NameNotFoundException e) {
				return 0; 
			} 
        } 
        public TextView getGenericView() {
            TextView textView = new TextView(ActivityPickerActivity.this);
            textView.setLayoutParams(lpGroup);
            textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
            textView.setPadding(leftPadding, 0, 0, 0);
            return textView;
        } 
        public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
                View convertView, ViewGroup parent) {
            TextView textView = getGenericView();
            ActivityInfo activity=getChild(groupPosition, childPosition);
            if(activity!=null){
	            String name=activity.name.replace(activity.packageName, "");
	        	textView.setText(activity.loadLabel(mPackageManager)+"("+name+")");
	        	textView.setLayoutParams(lpChild);
            } 

8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setGravity, setPadding, setText, setTextSize
		playerText.setText(score.getPlayer());
		playerText.setGravity(Gravity.LEFT);
		playerText.setPadding(10, 10, 10, 10);
		playerText.setTextSize(16);
 
		TextView scoreText = new TextView(parent.getContext());
		scoreText.setText(String.valueOf(score.getScore()));
		scoreText.setGravity(Gravity.RIGHT);
		scoreText.setPadding(10, 10, 10, 10);
		scoreText.setTextSize(16);
 
		layout.addView(playerText);
		layout.addView(scoreText);
 
		return layout;
	} 
 
	public List<HighScore> getScores() {
		return scores;
	} 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setLayoutParams, setGravity, setText
         * instance number. 
         */ 
        @Override 
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            TextView tv = new TextView(getActivity());
            tv.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));
            tv.setText("Fragment #" + mNum);
            tv.setGravity(CENTER);
            return tv;
        } 
 
    } 
} 
 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setLayoutParams, setGravity, setPadding, setText
        public TextView getGenericView() {
            // Layout parameters for the ExpandableListView 
            AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, 64);
 
            TextView textView = new TextView(ExpandableList1.this);
            textView.setLayoutParams(lp);
            // Center the text vertically 
            textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
            // Set the text starting position 
            textView.setPadding(36, 0, 0, 0);
            return textView;
        } 
         
        public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
                View convertView, ViewGroup parent) {
            TextView textView = getGenericView();
            textView.setText(getChild(groupPosition, childPosition).toString());
            return textView;
        } 

8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setId, setGravity
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        FrameLayout root = new FrameLayout(getActivity());
 
        TextView tv = new TextView(getActivity());
        tv.setId(INTERNAL_EMPTY_ID);
        tv.setGravity(Gravity.CENTER);
        root.addView(tv, new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
 
        ExpandableListView lv = new ExpandableListView(getActivity());
        lv.setId(android.R.id.list);
        lv.setDrawSelectorOnTop(false);
        root.addView(lv, new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
 
        ListView.LayoutParams lp = new ListView.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
        root.setLayoutParams(lp);
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setGravity, setMaxWidth, setMinWidth, setPadding, setText
	public void removeItemAt(int pos) {
		this.messages.remove(pos);
	} 
 
	public View getView(int pos, View convertView, ViewGroup parent) {
		TextView messageText = new TextView(parent.getContext());
		messageText.setText(this.getMessageText(pos));
		messageText.setGravity(Gravity.LEFT);
		messageText.setPadding(10, 10, 10, 10);
		messageText.setMaxWidth(200);
		messageText.setMinWidth(200);
		messageText.setTextSize(16);
 
		return messageText;
	} 
 
	private String extractMessageFromJsonObject(String json) {
		try { 
			ObjectMapper mapper = new ObjectMapper();
			Map<String, Object> jsonDic = mapper.readValue(json,
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setId, setLayoutParams, setGravity, setText, setTextColor
				RelativeLayout.LayoutParams.WRAP_CONTENT,
				RelativeLayout.LayoutParams.WRAP_CONTENT);
		titleparams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
		titleparams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
 
		final TextView title = new TextView(getContext());
		title.setText(getTitle());
		title.setTextSize(24);
		title.setTextColor(Color.WHITE);
		title.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
		title.setGravity(Gravity.LEFT);
		title.setLayoutParams(titleparams);
		title.setId(TITLE_ID);
 
		layout.addView(title);
		layout.setOnClickListener(this);
		layout.setId(android.R.id.widget_frame);
 
		return layout;
		 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getHeight, setGravity, setText, setTextColor, setTextSize
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related TextView setGravity Questions & Answers:

setGravity Method Overview
Sets the horizontal alignment of the text and the vertical gravity that will be used when there is extra space in the TextView beyond what is required for the text itself.
See Code Examples for other Android TextView Methods: