Expand TextView with wrap_content until the neighbor view reaches the end of the parent

You can archive this layout by TableLayout and shrinkColumns attribute. <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”vertical” android:layout_width=”match_parent” android:layout_height=”match_parent”> <!– Row 1 –> <TableLayout android:layout_width=”match_parent” android:layout_height=”wrap_content” android:shrinkColumns=”0″> <TableRow android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:gravity=”center_vertical”> <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:padding=”4dp” android:maxLines=”1″ android:ellipsize=”end” android:text=”abcdefghijklmnopqrstuvwxyz”/> <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:padding=”4dp” android:maxLines=”1″ android:ellipsize=”none” android:text=”rightText”/> </TableRow> </TableLayout> <!– Row 2 –> <TableLayout android:layout_width=”match_parent” android:layout_height=”wrap_content” android:shrinkColumns=”0″> <TableRow … Read more

Scale background image to wrap content of layout

I had the same problem (I think), and the only solution I could find was this: <RelativeLayout android:layout_width=”match_parent” android:layout_height=”wrap_content” > <View android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:background=”@drawable/some_image” android:layout_alignTop=”@+id/actual_content” android:layout_alignBottom=”@id/actual_content” android:layout_alignLeft=”@id/actual_content” android:layout_alignRight=”@id/actual_content” /> <LinearLayout android:id=”@id/actual_content” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:layout_alignParentTop=”true” > <!– more stuff … –> </LinearLayout> </RelativeLayout>

Circular dependencies cannot exist in RelativeLayout, android?

The problem is caused because there is a circular reference in the layout parameters. For example, when view B is layout_below view A, view A can’t reference view B anymore in it’s below, alignRight etc. This can also exist between multiple views: A references B references C. In that scenario C can’t reference A because … Read more

Android Relative Layout Align Center

This will work: <?xml version=”1.0″ encoding=”utf-8″?> <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:paddingRight=”15dp” > <ImageView android:id=”@+id/place_category_icon” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_centerVertical=”true” android:contentDescription=”ss” android:paddingTop=”10dp” android:src=”@drawable/ic_launcher” /> <TextView android:id=”@+id/place_distance” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_alignParentRight=”true” android:layout_centerVertical=”true” android:text=”320″ /> <TextView android:id=”@+id/place_title” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_centerVertical=”true” android:layout_marginLeft=”15dp” android:layout_toRightOf=”@+id/place_category_icon” android:text=”Place Name” android:textColor=”#FFFF00″ android:textSize=”14sp” android:textStyle=”bold” /> </RelativeLayout>

How to avoid overlap view in relative layout in android?

Use layout_toStartOf in the first item with second item +id under double quotes <?xml version=”1.0″ encoding=”utf-8″?> <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:layout_height=”match_parent” android:orientation=”horizontal” > <TextView android:id=”@+id/email” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_alignParentLeft=”true” android:layout_centerVertical=”true” android:layout_toStartOf=”@+id/selectaccount” android:text=”very long text which used to overlap over radio button” android:textAppearance=”?android:attr/textAppearanceMedium” /> <RadioButton android:id=”@+id/selectaccount” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_alignParentRight=”true” android:layout_centerVertical=”true” /> </RelativeLayout> note this argument in textview android:layout_toStartOf=”@+id/selectaccount” … Read more

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

ImageView fills parent’s width OR height, but maintains aspect ratio

These: android:layout_height=”wrap_content” android:scaleType=”fitStart” android:adjustViewBounds=”true” should resize the image and change the size of the bounds to fit the new image size. If it does not do that on your device post the image you are using and what device you are testing on.

Create a new TextView programmatically then display it below another TextView

If it’s not important to use a RelativeLayout, you could use a LinearLayout, and do this: LinearLayout linearLayout = new LinearLayout(this); linearLayout.setOrientation(LinearLayout.VERTICAL); Doing this allows you to avoid the addRule method you’ve tried. You can simply use addView() to add new TextViews. Complete code: String[] textArray = {“One”, “Two”, “Three”, “Four”}; LinearLayout linearLayout = new … Read more

Can’t resize a RelativeLayout inside a ScrollView to fill the whole screen

I have faced this problem before. Just Use android:fillViewport=”true” in your scrollview and it will fill up the screen. <ScrollView xmlns:android=”http://schemas.android.com/apk/res/android” android:id=”@+id/scrollView1″ android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:fillViewport=”true” >