Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set android:layout_toLeftOf programmatically?

I have a RelativeLayout where I have one TextView and this element has its android:layout_toLeftOf attribute set to another TextView in this same layout.

Depending on the data received by the app from the server, I need to set the visibility of this one TextView to GONE and set the visibility of a ProgressBar to VISIBLE and then I need the first TextView left align with this Progress bar.

Is this possible to accomplish programmatically?

If not, could you think of a way to tackle the issue?

EDIT

Following below advice, this is how my working code looks like:

TextProgressBar txtProgressBar = (TextProgressBar) v.findViewById(R.id.progressBarPointsInProgress);
TextView offerName = (TextView) v.findViewById(R.id.textViewOfferName);
android.widget.RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)offerName.getLayoutParams();
params.addRule(RelativeLayout.LEFT_OF, R.id.progressBarPointsInProgress);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
offerName.setLayoutParams(params);
like image 776
Felipe Caldas Avatar asked Dec 28 '12 14:12

Felipe Caldas


1 Answers

addRule

RelativeLayout.Layoutparams params = (RelativeLayout.LayoutParams)ProgressBar.getLayoutParams();
params.addRule(RelativeLayout.LEFT_OF, R.id.youtTextView);
like image 103
Archie.bpgc Avatar answered Nov 07 '22 16:11

Archie.bpgc