Friday, February 27, 2015

Design Android Layout using Relative Layout

Field with text view and edit text as single field.

1.Textview on the left and edittext on the right side merged together as single field
2.Below are the code to create the above view

USE RELATIVE LAYOUT TO CREATE ABOVE VIEW

 <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" >

                        <TextView
                            android:id="@+id/ic_text_label49"
                            style="@style/CT_com_ic_edit_texview"
                            android:layout_width="50dp"
                            android:layout_height="40dp"
                            android:background="@drawable/rounded_textview"
                            android:text="@string/text_view49" />

                        <EditText
                            android:id="@+id/text49"
                            style="@style/CT_com_ictextbox"
                            android:layout_width="250dp"
                            android:layout_height="40dp"
                            android:layout_toRightOf="@+id/ic_text_label49"
                            android:background="@drawable/rounded_edittext"
                            android:imeOptions="actionNext"
                            android:singleLine="true" />
                    </RelativeLayout> 
 


TEXTVIEW STYLE AS FOLLOWS

<style name="CT_com_ic_edit_texview">
        <item name="android:textSize">18sp</item>
        <item name="android:gravity">center</item>
        <item name="android:layout_marginTop">20dp</item>
    </style> 
<style name="CT_com_ictextbox"> <item name="android:textSize">18sp</item> <item name="android:gravity">right|center_vertical</item> <item name="android:paddingRight">20dp</item> <item name="android:hint">.00</item> <item name="android:inputType">numberDecimal</item> <item name="android:layout_marginTop">20dp</item> <item name="android:imeOptions">actionNext</item> </style> 



NOW THE BACKGROUND VALUES ARE AS FOLLOWS 1.Background style for text view create a file name (rounded_textview)in my case and your own name and place the below code in that.
<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
 
    <!-- view background color -->
    <solid
        android:color="#D4E3F5" >
    </solid>
 
    <!-- view border color and width -->
    <stroke
        android:width="1dp"
        android:color="#2B65BC" >
    </stroke>
 
    <!-- If you want to add some padding -->
    <padding
        android:left="4dp"
        android:top="4dp"
        android:right="4dp"
        android:bottom="4dp"    >
    </padding>
 
    <!-- Here is the corner radius -->
    <corners
        android:topLeftRadius="6dp" 
        android:bottomLeftRadius="6dp">
    </corners>
 
</shape> 
 

2.Now the background style for edit text
create a file name (rounded_edittext)in my case and your own name and place the below code in that.

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
 
    <!-- view border color and width -->
    <stroke
        android:width="1dp"
        android:color="#2B65BC" >
    </stroke>
 
    <!-- If you want to add some padding -->
    <padding
        android:left="4dp"
        android:top="4dp"
        android:right="4dp"
        android:bottom="4dp"    >
    </padding>
 
    <!-- Here is the corner radius -->
    <corners
        android:topRightRadius="6dp" 
        android:bottomRightRadius="6dp">
    </corners>
 <!-- view background color -->
   <solid
       android:color="#FFFFFF" >
   </solid>
</shape>

1 comment:

  1. Slot Casino NJ Review & Promotions - Dr.MD
    The slot casino app is part of the growing number 전주 출장샵 of casino platforms around 양주 출장샵 the world. to the free spins bonus and you 의왕 출장마사지 will have 김포 출장안마 a chance to win the slot 정읍 출장마사지

    ReplyDelete