Android: 2 relative layout divided in half screen

Another way to accomplish the same task without needing to use a LinearLayout is to put a center-aligned “shim” in the middle of the parent layout, then align other elements to it. If you set the half-width element’s width to match_parent, but align both their left and right sides, they’ll end up shrinking themselves to … Read more

Android RelativeLayout below 2 views

Here you go: <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:orientation=”vertical” android:background=”@drawable/single_row” android:padding=”12dip”> <RelativeLayout android:layout_width=”wrap_content” android:layout_height=”wrap_content”> <ImageView android:id=”@+id/page_image” android:layout_marginRight=”6dip” android:layout_width=”66dip” android:layout_height=”66dip” android:layout_alignParentLeft=”true” android:src=”https://stackoverflow.com/questions/3355808/@drawable/no_photo” /> <TextView android:id=”@+id/page_name” style=”@style/pulse_content” android:layout_alignTop=”@id/page_image” android:layout_toRightOf=”@id/page_image” android:layout_width=”wrap_content” android:layout_height=”wrap_content” /> <TextView android:id=”@+id/page_desc” android:layout_below=”@id/page_name” style=”@style/pulse_content” android:layout_alignLeft=”@id/page_name” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Principal Consultant” /> </RelativeLayout> <Button android:id=”@+id/follow_button” android:layout_marginTop=”15dip” android:text=”Follow” style=”@style/follow_button” /> </LinearLayout>

FrameLayout vs RelativeLayout for overlays

A common rule of thumb when choosing layouts is to select the combination that results in the smallest number of nested layout views. Specific to your question, RelativeLayout is larger and more capable than the much simpler FrameLayout. So for simple layouts, the latter is probably more efficient. But if using RelativeLayout and it’s added … Read more

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

LinearLayout vs RelativeLayout [closed]

Read this article: The Android UI toolkit offers several layout managers that are rather easy to use and, most of the time, you only need the basic features of these layout managers to implement a user interface. Sticking to the basic features is unfortunately not the most efficient way to create user interfaces. A common … Read more

How to create a RelativeLayout programmatically with two buttons one on top of the other?

I have written a quick example to demonstrate how to create a layout programmatically. public class CodeLayout extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Creating a new RelativeLayout RelativeLayout relativeLayout = new RelativeLayout(this); // Defining the RelativeLayout layout parameters. // In this case I want to fill its parent RelativeLayout.LayoutParams rlp … Read more

Overlapping Views in Android

Android handles transparency across views and drawables (including PNG images) natively, so the scenario you describe (a partially transparent ImageView in front of a Gallery) is certainly possible. If you’re having problems it may be related to either the layout or your image. I’ve replicated the layout you describe and successfully achieved the effect you’re … Read more