Legend and set of fields in android

I want to know if it is possible to make this form in android:

enter image description here

At this point, I created a form to create a border (I use this form as the background of my linear output, but I donโ€™t know how to deal with text).

Thanks in advance.

+7
source share
1 answer

I managed to get a frame with a header using the following technique.

  • Use FrameLayout for general layout.

  • Inside add another layout for your main content - it could be anything. For the background of this layout, use your own XML drawing with stroke to draw the frame. Remember to add fields to this layout, especially marginTop , since you need a place to display the frame title. Also add some indentation to make it more enjoyable.

  • Use a TextView with an opaque background and some paddings as a title. Set marginLeft valid value to offset the title on the left.

Here is my XML for this:

 <?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="fill_parent" android:background="@android:color/white"> <!-- This is the main content --> <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margin="15dp" android:background="@drawable/frame" android:orientation="vertical" android:padding="20dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Main Content" android:layout_centerInParent="true" /> </RelativeLayout> <!-- This is the title label --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@android:color/white" android:padding="5dp" android:text="Testing" android:layout_marginLeft="30dp" android:textColor="@android:color/black" /> </RelativeLayout> 

On execution, I get this in the application:

enter image description here

Feel free to customize the fields / paddings to align the title as you need.

+22
source