How to switch from the default ConstraintLayout to RelativeLayout in Android Studio

Well, I saw the answer above and it worked for me too. But, I gave it a shot, and succeded converting my current project to Relative Layout. Do as follows: At activity_main.xml tab, change it to text. At the top of it, you’ll find the following: <android.support.constraint.ConstraintLayout xmlns:android=”http://schemas.android.com/apk/res/android” Just change all before xmlns to RelativeLayout. … Read more

Listview error: “Your content must have a ListView whose id attribute is ‘android.R.id.list'”

You are probably using a ListActivity. In you firstlist.xml replace the id to: <ListView android:id=”@android:id/list” … ListActivity looks for the id R.android.id.list which you in xml is @android:id/list. Also look at this post: ListView whose id attribute is ‘android.R.id.list’ Error when I have the ListView id set correctly

How to add a view programmatically to RelativeLayout?

Heres an example to get you started, fill in the rest as applicable: TextView tv = new TextView(mContext); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); params.leftMargin = 107 … mRelativeLayout.addView(tv, params); The docs for RelativeLayout.LayoutParams and the constructors are here

How do I programmatically remove an existing rule that was defined in XML?

You can’t remove a rule because all rules are always stored in a fixed-size java array. But you can set a rule to 0. For example layoutParams.addRule(RelativeLayout.RIGHT_OF, 0); layoutParams.addRule(RelativeLayout.BELOW, R.id.new_ref_LinearLayout); EDIT (thanks to Roger Rapid): As of API level 17, the class RelativeLayout.LayoutParams has the following method: public void removeRule(int verb) So you can remove … Read more

Extending RelativeLayout, and overriding dispatchDraw() to create a zoomable ViewGroup

If you are applying a scale factor to the drawing of your children, you also need to apply the appropriate scale factor to all of the other interactions with them — dispatching touch events, invalidates, etc. So in addition to dispatchDraw(), you will need to override and appropriate adjust the behavior of at least these … Read more

Can I Set “android:layout_below” at Runtime Programmatically?

Yes: RelativeLayout.LayoutParams params= new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT); params.addRule(RelativeLayout.BELOW, R.id.below_id); viewToLayout.setLayoutParams(params); First, the code creates a new layout params by specifying the height and width. The addRule method adds the equivalent of the xml properly android:layout_below. Then you just call View#setLayoutParams on the view you want to have those params.

Moving from one activity to another Activity in Android

First You have to use this code in MainActivity.java class @Override public void onClick(View v) { // TODO Auto-generated method stub Intent i = new Intent(getApplicationContext(),NextActivity.class); startActivity(i); } You can pass intent this way. Second add proper entry into manifest.xml file. <activity android:name=”.NextActivity” /> Now see what happens.