how to add multiple frames in xml - android

Hi in the below xml using drawable i was added frame.Now,for single one I am displaying personal information In the same way how to display multiple but title should be different.
How do that one any one can help me.
updated
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/frame1">
<RelativeLayout
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="280dp"
android:layout_margin="15dp"
android:background="#drawable/frame1"
android:orientation="vertical"
android:padding="20dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center|center_vertical"
android:background="#DFECEB"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginTop="20dp"
android:padding="5dp"
android:text="First Name:"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="15sp"
android:textStyle="bold" />
<EditText
android:id="#+id/first_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:background="#drawable/rounded"
android:cursorVisible="true"
android:padding="5dp"
android:singleLine="true"
android:textColor="#000000" >
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginTop="10dp"
android:padding="5dp"
android:text="Last Name:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15sp"
android:textStyle="bold" />
<EditText
android:id="#+id/last_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:background="#drawable/rounded"
android:cursorVisible="true"
android:inputType="textPassword"
android:padding="5dp"
android:singleLine="true"
android:textColor="#000000" >
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginTop="10dp"
android:padding="5dp"
android:text="Email:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15sp"
android:textStyle="bold" />
<EditText
android:id="#+id/email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:background="#drawable/rounded"
android:cursorVisible="true"
android:inputType="textPassword"
android:padding="5dp"
android:singleLine="true"
android:textColor="#000000" >
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginTop="10dp"
android:padding="5dp"
android:text="Mobile No."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15sp"
android:textStyle="bold" />
<EditText
android:id="#+id/mobile_no"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:background="#drawable/rounded"
android:cursorVisible="true"
android:inputType="textPassword"
android:padding="5dp"
android:singleLine="true"
android:textColor="#000000" >
</EditText>
</LinearLayout>
</LinearLayout>
</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="Personal Information"
android:layout_marginLeft="30dp" android:textColor="#android:color/black" />
</RelativeLayout>
</FrameLayout>
</LinearLayout>

Am not 100% sure , what you are asking. If my understanding is correct, you want to wrap the frame . If so, try editing your Relative layouts height to Wrapcontent.
<RelativeLayout
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_margin="5dp" android:background="#drawable/frame1"
android:orientation="vertical" android:padding="5dp">

Related

How make list elements right align?

How can I make textview_item_discounted_price right aligned? Here is my layout file for list elements:
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:id="#+id/imageview_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#color/item_background_color"
android:contentDescription="#string/hello"
android:scaleType="matrix" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.8"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textview_item_code"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:singleLine="true"
android:textIsSelectable="false"
android:textStyle="bold" >
</TextView>
<TextView
android:id="#+id/textview_item_name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:singleLine="true"
android:textIsSelectable="false" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/textview_item_rem"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:singleLine="true"
android:textIsSelectable="false"
android:textStyle="italic" >
</TextView>
<TextView
android:id="#+id/textview_item_discounted_price"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:singleLine="true"
android:textIsSelectable="false"
android:textStyle="italic" >
</TextView>
</LinearLayout>
</LinearLayout>
<EditText
android:id="#+id/edittext_quantity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:focusable="true"
android:gravity="right"
android:hint="#string/doc_add_item_quantity_hint"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:singleLine="true" >
</EditText>
I solve this with the following way:
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:id="#+id/imageview_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#color/item_background_color"
android:contentDescription="#string/hello"
android:scaleType="matrix" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.8"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textview_item_code"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:singleLine="true"
android:textIsSelectable="false"
android:textStyle="bold" >
</TextView>
<TextView
android:id="#+id/textview_item_name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:singleLine="true"
android:textIsSelectable="false" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/textview_item_rem"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:singleLine="true"
android:textIsSelectable="false"
android:textStyle="italic" >
</TextView>
<TextView
android:id="#+id/textview_item_discounted_price"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="right"
android:singleLine="true"
android:textIsSelectable="false"
android:textStyle="italic" >
</TextView>
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.9" />
</LinearLayout>
</LinearLayout>
<EditText
android:id="#+id/edittext_quantity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:focusable="true"
android:gravity="right"
android:hint="#string/doc_add_item_quantity_hint"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:singleLine="true" >
</EditText>
Set android:gravity="right" and the text will move to the right of the TextView
android:alignParentRight="true" will move the TextView to the right end of the LinearLayout
try out this:
<TextView
android:id="#+id/textview_item_rem"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:singleLine="true"
android:textIsSelectable="false"
android:textStyle="italic"
android:gravity="right" >
</TextView>
Check This:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageview_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:contentDescription="hello"
android:scaleType="matrix" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textview_item_code"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:singleLine="true"
android:text="hello"
android:textIsSelectable="false"
android:textStyle="bold" >
</TextView>
<TextView
android:id="#+id/textview_item_name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:singleLine="true"
android:text="hello"
android:textIsSelectable="false" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/textview_item_rem"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:singleLine="true"
android:text="hello"
android:textIsSelectable="false"
android:textStyle="italic" >
</TextView>
]</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="0.1"
android:orientation="vertical">
<TextView
android:id="#+id/textview_item_discounted_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:gravity="right"
android:singleLine="true"
android:text="hello"
android:textIsSelectable="false"
android:textStyle="italic" >
</TextView>
</LinearLayout>
<EditText
android:id="#+id/edittext_quantity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:focusable="true"
android:gravity="right"
android:hint="quantity_hint"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:singleLine="true" >
</EditText>
</LinearLayout>
</LinearLayout>

how to align fields in android?

Hi
I am making a simple example in android but My problem is that
my textview and editfield is not align.It mean that
it should look like that
![Name editView
Rollnumber editView
Button on center][2]
It look like this
here is my code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/text_view_boat1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
/>
<EditText
android:id="#+id/entry"
android:hint="add name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/text_view_boat2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Roll Number"
/>
<EditText
android:id="#+id/entry2"
android:hint="add roll number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me"
android:id="#+id/clickme"
/>
</LinearLayout>
Use TableLayout instead :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:shrinkColumns="1"
android:stretchColumns="1" >
<TableRow
android:descendantFocusability="beforeDescendants"
android:focusable="true"
android:focusableInTouchMode="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name :" />
<EditText
android:id="#+id/companyIdEditText_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:enabled="false"/>
</TableRow>
<TableRow
android:descendantFocusability="beforeDescendants"
android:focusable="true"
android:focusableInTouchMode="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RollNumber :" />
<EditText
android:id="#+id/companyNameEditText_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</TableRow>
</TableLayout>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="ClickMe"/>
</LinearLayout>
You can use the attribute weight. Set the the width of the row's chrildren to 0dp
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/text_view_boat2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Roll Number"
/>
<EditText
android:id="#+id/entry2"
android:hint="add roll number"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="2"
/>
</LinearLayout>
try this one...
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/text_view_boat1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="05dp"
android:text="Name" />
<EditText
android:id="#+id/entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/text_view_boat1"
android:layout_marginRight="05dp"
android:layout_toRightOf="#id/text_view_boat1"
android:hint="add name" />
<LinearLayout
android:id="#+id/lin_lay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/entry"
android:layout_marginTop="05dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/text_view_boat2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Roll Number" />
<EditText
android:id="#+id/entry2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="add roll number" />
</LinearLayout>
<Button
android:id="#+id/clickme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/lin_lay"
android:layout_marginTop="05dp"
android:text="Click Me" />

Set a LinearLayout to scroll

I have been reading many posts here in stackoverflow about making a linear layout scroll and have applied all the specific advices to make it work but it still does not show on the left hand side. I am new to android and not sure what i am doing wrong.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/scrollView1">
<LinearLayout
android:id="#+id/expense"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="start"
android:orientation="vertical"
tools:context=".Expense" >
<LinearLayout
android:id="#+id/tedsts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/rounded"
android:clickable="true"
android:weightSum="1.0" >
<TextView
android:id="#+id/testffg"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".30"
android:text="Matter"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/tedssss"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".65"
android:ellipsize="end"
android:paddingLeft="10dp"
android:singleLine="true"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<ImageView
android:layout_width="15dp"
android:layout_height="wrap_content"
android:layout_weight="0.05"
android:src="#drawable/r_arrow" />
</LinearLayout>
<TextView
android:id="#+id/tetxttx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginLeft="0dp"
android:layout_marginRight="10dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/gray_dark"
android:visibility="invisible" />
<EditText
android:id="#+id/teetttsss"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/rounded_all"
android:ems="10"
android:gravity="top"
android:hint="dgdfgfgf"
android:inputType="textMultiLine" />
<LinearLayout
android:id="#+id/tesssstt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/rounded_all_clickable_selector"
android:clickable="true"
android:weightSum="1.0" >
<TextView
android:id="#+id/yttrree"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".20"
android:text="Date"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/rrrefffe"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".75"
android:ellipsize="end"
android:paddingLeft="10dp"
android:singleLine="true"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<ImageView
android:layout_width="15dp"
android:layout_height="wrap_content"
android:layout_weight="0.05"
android:src="#drawable/r_arrow" />
</LinearLayout>
<RadioButton
android:id="#+id/dfgrrrrr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginTop="5dp"
android:text="Cost"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/gergrerrr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-4dp"
android:background="#drawable/rounded_all_clickable"
android:ems="10"
android:hint=""
android:inputType="numberDecimal"
android:singleLine="true" >
</EditText>
<RadioButton
android:id="#+id/rerreee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginTop="5dp"
android:text="Time"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/gggrrrrre"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/roundede"
android:ems="10"
android:hint="grrrergg."
android:inputType="numberDecimal"
android:singleLine="true"
android:visibility="gone" >
</EditText>
<EditText
android:id="#+id/65gfhhggf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-4dp"
android:background="#drawable/rounded"
android:ems="10"
android:hint=""
android:inputType="numberDecimal" >
</EditText>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/gfhgfhtrhrth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="50dp"
android:layout_marginTop="15dp"
android:visibility="gone" />
<TextView
android:id="#+id/ghjjhhhgh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="30dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/expense_TV_total"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageButton
android:id="#+id/hgjhhghjhg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/save_selector" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
use this :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView ...>
<LinearLayout ...>
...
...
</LinearLayout>
</ScrollView>
and set hieght to
android:layout_height="wrap_content"
as Karakuri said
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
//Your Main Layout
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="100">
// First Sub Layout Under Main Layout
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_weight="10"
android:weightSum="100" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="TextView"
android:layout_weight="70" />
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="30" />
</LinearLayout>// Finishing First Sub layout
// Second Sub Layout Under Main Layout
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_weight="10"
android:weightSum="100" >
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="TextView"
android:layout_weight="70" />
<EditText
android:id="#+id/editText2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="30" />
</LinearLayout>// Finishing Second Sub layout
similarly for 3rd,4rth,5th sub layouts and so on........
</LinearLayout> // Finishing Main Layout
</ScrollView> // Finishing ScrollView
Make the child of the ScrollView have android:layout_height="wrap_content" (currently yours has match_parent)
add
android:layout_width="match_parent"
android:layout_height="match_parent"
to your root ScrollView
I hope this code may be help you.
android:layout_width="match_parent"
android:layout_height="match_parent">

How to align textview and edittext?

I have a layout like this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/bg_color"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/header"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="TITLE"
/>
</LinearLayout>
<TextView
android:id="#+id/info_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:gravity="top|center_horizontal"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dip"
android:background="#drawable/box_bg" >
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dip"
android:ems="10"
android:gravity="center"
android:singleLine="true" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/txtText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/editText"
android:layout_below="#+id/editText"
android:layout_marginTop="2dip"
android:clickable="true"
android:text="Text1"
/>
<TextView
android:id="#+id/txtText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/txtText1"
android:layout_alignLeft="#+id/editText"
android:layout_below="#+id/editText"
android:layout_marginLeft="10dip"
android:layout_toLeftOf="#+id/txtText1"
android:clickable="true"
android:gravity="left"
android:text="Text2"
/>
</RelativeLayout>
</LinearLayout>
I want to align the txtText1 below editText and align the right ide of both views. Align left side of txtText2 with editText. But it seems to be does not work when placing the EditText as center-horizontal.How can i make it ?
Thanks in Advance
Try this code..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/topLL"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="TITLE" />
</LinearLayout>
<TextView
android:id="#+id/info_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/topLL"
android:layout_marginTop="5dip"
android:gravity="top|center_horizontal" />
<LinearLayout
android:id="#+id/reLL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/info_text"
android:layout_gravity="center_vertical"
android:background="#ccc"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical" >
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dip"
android:ems="10"
android:gravity="center_horizontal"
android:singleLine="true" >
<requestFocus />
</EditText>
<LinearLayout
android:id="#+id/textLL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2" >
<TextView
android:id="#+id/txtText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="10dip"
android:layout_weight="1"
android:clickable="true"
android:gravity="left"
android:text="Text2" />
<TextView
android:id="#+id/txtText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:clickable="true"
android:gravity="right"
android:text="Text1" />
</LinearLayout>
</LinearLayout>

Gravity for Linear Layout

Can anyone help me in giving the gravity for four buttons developed in a vertical linear layout which is again in horizontal linear layout with progress bar. I need the whole buttons and the progress bar in the bottom of my screen. Please help me out.
Thanks in advance
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<Button
android:id="#+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="#+id/pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/fwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:id="#+id/progressbar_Horizontal"
/>
</LinearLayout>
Hi # srinivas.
gravity for four buttons developed in a vertical linear layout which is again in horizontal
linear layout with progress bar, try out by this xml code.. its must helpful to you...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white"
android:orientation="vertical" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="3" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="First Name"
android:textColor="#000000" />
<EditText
android:id="#+id/firstName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/editbox_background_normal"
android:ems="10"
android:hint="First Name"
android:maxLength="20"
android:singleLine="true"
android:textColor="#000000" >
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="3" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Last Name"
android:textColor="#000000" />
<EditText
android:id="#+id/lastName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/editbox_background_normal"
android:ems="10"
android:hint="Last Name"
android:maxLength="20"
android:singleLine="true"
android:textColor="#000000" >
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="3" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="UserName"
android:textColor="#000000" />
<EditText
android:id="#+id/un"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/editbox_background_normal"
android:ems="10"
android:hint="User Name"
android:maxLength="20"
android:singleLine="true"
android:textColor="#000000" >
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="3" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Password"
android:textColor="#000000" />
<EditText
android:id="#+id/pw"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/editbox_background_normal"
android:ems="10"
android:hint="Password"
android:maxLength="20"
android:password="true"
android:singleLine="true"
android:textColor="#000000" >
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="3" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Email"
android:textColor="#000000" />
<EditText
android:id="#+id/email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/editbox_background_normal"
android:ems="10"
android:hint="Email"
android:maxLength="20"
android:singleLine="true"
android:textColor="#000000" >
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="3" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Phone No."
android:textColor="#000000" />
<EditText
android:id="#+id/phoneNum"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/editbox_background_normal"
android:ems="10"
android:hint="Phone Number"
android:inputType="number"
android:maxLength="20"
android:singleLine="true"
android:textColor="#000000" >
</EditText>
</LinearLayout>
<Button
android:id="#+id/push_button"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/rounded_button"
android:text="Send Data"
android:textColor="#ffffff" />
</LinearLayout>
</ScrollView>
</LinearLayout>
android:gravity="bottom"
add this line to both your vertical as well as horizontal linear layout
I guess this was the answer you were looking for
Replace with following code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="#+id/btnLayout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/progressbar_Horizontal"
>
<Button
android:id="#+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="#+id/pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/fwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:id="#+id/progressbar_Horizontal"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>

Categories

Resources