Mc Sam Mc Sam - 5 months ago 16
Android Question

Android - Need Suggestion for creating a form view

I want to create a "create task" activity that look similar like this. Any suggestion what layout i should use in order to have a neat view?

enter image description here

Answer

In order to build a neat view like the one you shown, you will need this layout structure which handles configuration changes such as device's size and orientation.

<ScrollView>

 <LinearLayout
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical">

     <!--TextViews' visibility should be set to VISIBLE when its EditText gets focus, and to GONE when it losts focus-->

     <TextView/>

     <EditText/>

     <TextView/>

     <EditText/>


     <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="horizontal">

        <ImageView/>

        <TextView/>

        <ImageView/>

        <ImageView/>

     </LinearLayout>

     <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="horizontal">

        <ImageView/>

        <TextView/>

     </LinearLayout>

     <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="horizontal">

        <SeekBar/>

     </LinearLayout>

     <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="horizontal">

        <ImageView/>

        <TextView/>

     </LinearLayout>

     <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="horizontal">

        <RadioGroup>

            <RadioButton/>
            <RadioButton/>

        </RadioGroup>

     </LinearLayout>


     <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="horizontal">

        <ImageView/>

        <TextView/>

        <ToggleButton/>

     </LinearLayout>

     <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="horizontal">

        <ImageView/>

        <TextView/>

        <Spinner/>

     </LinearLayout>

 </LinearLayout>

</ScrollView>

You could take a look at http://www.flaticon.com/ to download some icons. Please credit the author of the drawable.

The Action Bar depends on the theme and styles you put on your activity, and default colors in your color.xml file.

I'll let you search for views' attributes, but it should look like the structure shown above.

EDIT

In order to align imageviews, you need to use horizontal oriented LinearLayout and apply a weigth to their children.

Here is how to align imageviews and textviews :

<LinearLayout
    android:orientation="horizontal"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:weightSum="4" />

    <ImageView
        android:layout_weight="1" />

    <TextView
        android:layout_weight="3" />

</LinearLayout>

This way, each ImageView will use 25% of its layout width.

You must set children's width to 0dp

Comments