I have the following XML layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="#layout/bginset2" >
<TextView
android:id="#+id/tvTripName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Trip Name:"
android:textStyle="bold"
android:textColor="#2B00E4"
android:layout_above="#+id/etShowLog"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingLeft="2dip" />
<EditText
android:id="#+id/etFileName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/tvTripName"
android:ems="10"
android:inputType="textNoSuggestions"
android:paddingLeft="2dip"
android:singleLine="true"
android:textColor="#999999"
android:textSize="14dip"
android:textStyle="normal" />
<EditText
android:id="#+id/etShowLog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine|textNoSuggestions"
android:lines="20"
android:textStyle="normal"
android:paddingLeft="2dip"
android:singleLine="false"
android:textColor="#999999"
android:textSize="14dip"
android:gravity="top"
android:layout_above="#+id/btnClear" />
<Button
android:id="#+id/btnClear"
android:background="#drawable/otherbuttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear Trip"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:shadowColor="#000000"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="2"
android:layout_alignParentBottom="true" />
<Button
android:id="#+id/btnSave"
android:background="#drawable/otherbuttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save Trip"
android:layout_gravity="right"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:shadowColor="#000000"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="2"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
</RelativeLayout>
It shows up on my phone like this:
Why does the Trip Name appear so low and why is the text so close to the left?
How do I fix it?
It looks like you have conflicting properties in your EditText
<EditText
android:id="#+id/etFileName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine|textNoSuggestions"
android:lines="22"
android:textStyle="normal"
android:paddingLeft="2dip"
android:singleLine="false"
android:textColor="#999999"
android:textSize="14dip"
android:layout_toLeftOf="#+id/tvTripName" // here
android:layout_alignParentRight="true" // and here
You are telling it to be to the left of your TextView which is aligned left but also telling it to be aligned right of parent.
you can keep your cursor according to your choice by using this
EditText.setSelection(int index)
and for Trip name..just put Textview and edittext inside one layout
like
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/tvTripName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="2dip"
android:text="Trip Name:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#2B00E4"
android:textStyle="bold" />
<EditText
android:id="#+id/etFileName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textNoSuggestions"
android:paddingLeft="2dip"
android:singleLine="true"
android:textColor="#999999"
android:textSize="14dip"
android:textStyle="normal" />
</LinearLayout>
<EditText
android:id="#+id/etShowLog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/btnClear"
android:ems="10"
android:gravity="top"
android:inputType="textMultiLine|textNoSuggestions"
android:lines="20"
android:paddingLeft="2dip"
android:singleLine="false"
android:textColor="#999999"
android:textSize="14dip"
android:textStyle="normal" />
<Button
android:id="#+id/btnClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/ic_launcher"
android:shadowColor="#000000"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="2"
android:text="Clear Trip"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<Button
android:id="#+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:background="#drawable/ic_launcher"
android:shadowColor="#000000"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="2"
android:text="Save Trip"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</RelativeLayout>
Hope this will work for u..
Related
I have just created an expandable RecyclerView with different views as every parent item have a child My case is when expanding parent item it view it's child with a vertical spacing between each child Item like this
as this is my main XML File
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#dedede"
tools:context="abtech.waiteriano.com.waitrer.MainPaymentActivity">
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="19dp"
android:background="#ffffff">
<EditText
android:id="#+id/checkNoET"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/imageView7"
android:editable="false"
android:ems="10"
android:gravity="right"
android:text="505050505050"
android:textSize="12dp">
<requestFocus />
</EditText>
<TextView
android:id="#+id/checkNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/checkNoET"
android:layout_alignBottom="#+id/checkNoET"
android:layout_marginStart="10dp"
android:layout_toEndOf="#+id/imageView7"
android:text="Check#"
android:textColor="#color/colorPrimary"
android:textSize="12dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView7"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/checkNoET"
android:layout_alignParentStart="true"
android:layout_alignTop="#+id/checkNoET"
app:srcCompat="#drawable/check" />
<EditText
android:id="#+id/editText"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/checkNoET"
android:layout_alignBottom="#+id/checkNoET"
android:layout_alignParentEnd="true"
android:editable="false"
android:ems="10"
android:gravity="end"
android:text="5"
android:textSize="12dp">
<requestFocus />
</EditText>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText"
android:layout_alignBottom="#+id/editText"
android:layout_alignStart="#+id/editText"
android:layout_marginStart="13dp"
android:text="Coves"
android:textColor="#color/colorPrimary"
android:textSize="12dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView8"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editText"
android:layout_toStartOf="#+id/editText"
app:srcCompat="#drawable/covers" />
<EditText
android:id="#+id/tableNo"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_below="#+id/checkNoET"
android:layout_toEndOf="#+id/imageView7"
android:editable="false"
android:ems="10"
android:gravity="end"
android:text="25"
android:textSize="12dp">
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tableNo"
android:layout_alignBottom="#+id/tableNo"
android:layout_alignStart="#+id/checkNo"
android:text="Table"
android:textColor="#color/colorPrimary"
android:textSize="12dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView9"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/checkNoET"
app:srcCompat="#drawable/tablepay" />
<EditText
android:id="#+id/editText14"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tableNo"
android:layout_alignBottom="#+id/tableNo"
android:layout_alignParentEnd="true"
android:editable="false"
android:text="15/10/2017 03:15PM"
android:textColor="#000000"
android:textSize="10dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView10"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editText14"
android:layout_toStartOf="#+id/editText14"
app:srcCompat="#drawable/calendar" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/relativeLayout2"
android:layout_marginTop="14dp"
android:background="#ffffff">
<android.support.v7.widget.RecyclerView
android:id="#+id/parentList"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="220dp"
android:layout_below="#+id/relativeLayout3"
android:layout_marginTop="10dp"
android:background="#ffffff">
<GridView
android:id="#+id/paymentsTypeGV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnWidth="80dp"
android:gravity="center"
android:horizontalSpacing="5dp"
android:numColumns="4"
android:stretchMode="columnWidth"
android:verticalSpacing="5dp"></GridView>
</RelativeLayout>
</RelativeLayout>
my problem is from my xml design and if i is from xml design the problem is in the parent list item ot the child list item or from the main XML File sorry if any thing is not clear enough
Here's a thought: try removing any padding on the text elements.
android:includeFontPadding="false"
If this works, then this answer will become duplicate to:
Android: TextView: Remove spacing and padding on top and bottom
This is what i am trying to achieve
But
this is what i get when uploaded on phone.
It seems ok in android studio fragment design preview but when uploaded on phone
checkboxes are not displayed :(.
Any better solutions?
Below is full xml code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:fitsSystemWindows="false"
tools:context=".MainFragment">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoText="false"
android:text="#string/getnotif"
android:layout_below="#+id/linearLayout5"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp" />
<CheckBox
android:id="#+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView"
android:layout_alignStart="#+id/textView"
android:layout_below="#+id/textView"
android:text="#string/mcall"
android:textSize="12sp" />
<CheckBox
android:id="#+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView"
android:layout_toEndOf="#+id/checkBox"
android:layout_toRightOf="#+id/checkBox"
android:text="#string/msms"
android:textSize="12sp" />
<Button
android:id="#+id/timePicker"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="00:00"
android:background="#3f51b5"
android:layout_alignTop="#+id/timePicker2"
android:layout_marginLeft="25dp"
android:layout_alignParentStart="true"
android:textColor="#ffffff" />
<Button
android:id="#+id/timePicker2"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="23:59"
android:background="#3f51b5"
android:layout_below="#+id/linearLayout4"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="false"
android:layout_alignParentEnd="false"
android:layout_marginRight="25dp"
android:layout_alignParentRight="true"
android:textColor="#ffffff" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/timePicker"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:layout_alignParentEnd="true">
<TextView
android:id="#+id/textView8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="0dp"
android:text="Days"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout"
android:orientation="horizontal"
android:layout_alignRight="#+id/linearLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<CheckBox
android:id="#+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:checked="false"
android:layout_weight="1"
android:text="#string/monday"
android:paddingLeft="-27dp"
android:paddingTop="40dp"
android:textSize="10dp" />
<CheckBox
android:id="#+id/checkBox4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:layout_weight="1"
android:text="#string/tuesday"
android:paddingLeft="-26dp"
android:paddingTop="40dp"
android:textSize="10dp" />
<CheckBox
android:id="#+id/checkBox5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:layout_weight="1"
android:text="#string/wednesday"
android:paddingLeft="-27dp"
android:paddingTop="40dp"
android:textSize="10dp" />
<CheckBox
android:id="#+id/checkBox6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:layout_weight="1"
android:text="#string/thursday"
android:paddingLeft="-27dp"
android:paddingTop="40dp"
android:textSize="10dp" />
<CheckBox
android:id="#+id/checkBox7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:layout_weight="1"
android:text="#string/friday"
android:paddingLeft="-24dp"
android:paddingTop="40dp"
android:textSize="10dp" />
<CheckBox
android:id="#+id/checkBox8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:checked="false"
android:layout_weight="1"
android:text="#string/saturday"
android:paddingLeft="-25dp"
android:paddingTop="40dp"
android:textSize="10dp" />
<CheckBox
android:id="#+id/checkBox9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:checked="false"
android:text="#string/sunday"
android:paddingLeft="-27dp"
android:paddingTop="40dp"
android:textSize="10dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal">
<Button
android:id="#+id/exitButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/button_state"
android:text="Exit"
android:layout_weight="0.5"
android:layout_marginRight="16dp"
android:textColor="#ffffff" />
<Button
android:id="#+id/saveButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/button_state"
android:text="Save"
android:layout_weight="0.5"
android:layout_marginLeft="16dp"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="false"
android:layout_marginTop="20dp"
android:id="#+id/linearLayout4"
android:layout_alignParentEnd="false">
<TextView
android:id="#+id/textView7"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/from"
android:layout_below="#+id/textView5"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="false"
android:gravity="center"
android:layout_marginTop="20dp"
android:layout_marginLeft="25dp" />
<TextView
android:id="#+id/textView23"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="0dp"
android:text="Time"
android:gravity="center"
android:layout_weight="1" />
<TextView
android:id="#+id/textView6"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/to"
android:layout_below="#+id/textView5"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:gravity="center"
android:layout_marginTop="20dp"
android:layout_marginRight="25dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout5"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:orientation="horizontal"
android:layout_below="#+id/linearLayout2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</LinearLayout>
</RelativeLayout>
Set all your checkboxes with layout_weight=1 inside a LinearLayout. Set the Linear Layout's orientation to vertical.
<?xml version="1.0" encoding="utf-8"?>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mon"
android:layout_weight="1"
android:id="#+id/checkBox"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tue"
android:layout_weight="1"
android:id="#+id/checkBox2"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Wed"
android:layout_weight="1"
android:id="#+id/checkBox3"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Thu"
android:layout_weight="1"
android:id="#+id/checkBox4"/>
I have tested your design in an activity , it's displaying fine in full screen.
[![like this][1]][1]
[1]: http://i.stack.imgur.com/0B1hz.png
Make sure you have given Fragment width and height to match parent.
<Fragment
android:width="match_parent"
android:height="match_parent"
/>
New androidtudio preview
And
the result on phone
Bellow is code modified as you suggested.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:fitsSystemWindows="false"
tools:context=".MainFragment">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoText="false"
android:text="#string/getnotif"
android:layout_below="#+id/linearLayout2"
android:layout_centerHorizontal="true" />
<CheckBox
android:id="#+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView"
android:layout_alignStart="#+id/textView"
android:layout_below="#+id/textView"
android:text="#string/mcall"
android:textSize="12sp" />
<CheckBox
android:id="#+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView"
android:layout_toEndOf="#+id/checkBox"
android:layout_toRightOf="#+id/checkBox"
android:text="#string/msms"
android:textSize="12sp" />
<Button
android:id="#+id/timePicker"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="00:00"
android:background="#3f51b5"
android:layout_alignTop="#+id/timePicker2"
android:layout_marginLeft="25dp"
android:layout_alignParentStart="true"
android:textColor="#ffffff" />
<Button
android:id="#+id/timePicker2"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="23:59"
android:background="#3f51b5"
android:layout_below="#+id/linearLayout4"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="false"
android:layout_alignParentEnd="false"
android:layout_marginRight="25dp"
android:layout_alignParentRight="true"
android:textColor="#ffffff" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/timePicker"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:layout_alignParentEnd="true">
<TextView
android:id="#+id/textView8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="0dp"
android:text="Days"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout"
android:orientation="vertical"
android:layout_alignRight="#+id/linearLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<CheckBox
android:id="#+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MON"
android:layout_weight="1" />
<CheckBox
android:id="#+id/checkBox4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TUE"
android:layout_weight="1"/>
<CheckBox
android:id="#+id/checkBox5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="WED"
android:layout_weight="1" />
<CheckBox
android:id="#+id/checkBox6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="THU"
android:layout_weight="1" />
<CheckBox
android:id="#+id/checkBox7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FRI"
android:layout_weight="1" />
<CheckBox
android:id="#+id/checkBox8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SAT"
android:layout_weight="1"/>
<CheckBox
android:id="#+id/checkBox9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SUN"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal">
<Button
android:id="#+id/exitButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/button_state"
android:text="Exit"
android:layout_weight="0.5"
android:layout_marginRight="16dp"
android:textColor="#ffffff" />
<Button
android:id="#+id/saveButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/button_state"
android:text="Save"
android:layout_weight="0.5"
android:layout_marginLeft="16dp"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="false"
android:layout_marginTop="20dp"
android:id="#+id/linearLayout4"
android:layout_alignParentEnd="false">
<TextView
android:id="#+id/textView7"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/from"
android:layout_below="#+id/textView5"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="false"
android:gravity="center"
android:layout_marginTop="20dp"
android:layout_marginLeft="25dp" />
<TextView
android:id="#+id/textView23"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="0dp"
android:text="Time"
android:gravity="center"
android:layout_weight="1" />
<TextView
android:id="#+id/textView6"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/to"
android:layout_below="#+id/textView5"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:gravity="center"
android:layout_marginTop="20dp"
android:layout_marginRight="25dp" />
</LinearLayout>
</RelativeLayout>
I didn't managed to align properly the text boxes under the check boxes.
I have inserted the layout into a scroll view and i can properly see all of them know.
It is good enough for me.
I have the code below and I face a problem with the image view "#+id/logo_skilfull" because it does not keep the aspect.. I think is because of the scaleType or the adjustViewBounds..
image in tablet
image in a phone (I want this)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayoutMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFF"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:keepScreenOn="true" >
<View
android:id="#+id/view"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/view2"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/view"
android:layout_centerHorizontal="true"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#drawable/registration_background"
android:orientation="vertical"
android:padding="25dp" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/member_login_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:text="Ingresá tu DNI"
android:textSize="25dp"
android:textStyle="bold"
android:typeface="monospace" />
<EditText
android:id="#+id/username_edtext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/member_login_tv"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:background="#drawable/register_uname"
android:gravity="center"
android:hint="Documento"
android:imeOptions="actionDone"
android:inputType="number"
android:singleLine="true"
android:textColor="#000000"
android:textSize="30dp"
android:textStyle="bold" />
<Button
android:id="#+id/login_button"
style="#style/button_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/username_edtext"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:background="#drawable/button_access"
android:text="Aceptar"
android:textColor="#ffffff" />
<ImageView
android:id="#+id/logo_skilfull"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/logos"
android:scaleType="matrix"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</LinearLayout>
<View
android:id="#+id/view2"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true" />
<ImageView
android:id="#+id/view_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:background="#drawable/member_imview" />
</RelativeLayout>
You should read about the ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
This is a problem changing the size of the View. You need to set scaleType.
Try fitStart.
<ImageView
android:id="#+id/logo_skilfull"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/logos"
android:scaleType="fitStart"
android:layout_alignParentBottom="true" />
How do I ensure the the multiline edittext that starts with "+++++++++++++++++" is right below when the keyboard is showing.
Right now it shows up like this:
http://imageshack.us/photo/my-images/21/pw95.png/
My XML code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="#drawable/bginset2" >
<TextView
android:id="#+id/tvTripName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Trip Name:"
android:textStyle="bold"
android:textColor="#2B00E4"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingLeft="2dp"
android:layout_marginTop="4dp" />
<EditText
android:id="#+id/etFileName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/tvTripName"
android:ems="10"
android:inputType="textNoSuggestions|textCapWords"
android:layout_marginLeft="2dp"
android:singleLine="true"
android:textColor="#569741"
android:textSize="16dp"
android:textStyle="bold"
android:maxLength="30" />
<EditText
android:id="#+id/etShowLog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine|textNoSuggestions"
android:lines="20"
android:textStyle="normal"
android:paddingLeft="2dip"
android:singleLine="false"
android:textColor="#999999"
android:textSize="14dp"
android:gravity="top"
android:layout_above="#+id/btnClear" />
<Button
android:id="#+id/btnClear"
android:background="#drawable/otherbuttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear Trip"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:shadowColor="#000000"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="2"
android:layout_alignParentBottom="true" />
<Button
android:id="#+id/btnSave"
android:background="#drawable/otherbuttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save Trip"
android:layout_gravity="right"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:shadowColor="#000000"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="2"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
</RelativeLayout>
How can I ensure, the any open space between the Trip Name and the two buttons below is taken up by the EditText regardless if the keyboard is out or not?
you need to set elements to be below one another so that when the keyboard comes up, they stay in their relative position.
for example to keep the edittext below the trip name textview you would do this
android:layout_below="#+id/tvTripName"
Hoping this is a simple one.
I have a layout that uses a scrollview. This was fine until I wanted to put an image and textview above it then have the scrollview with my edittexts below it.
At the moment I'm getting the following errors:
01-22 20:13:32.228: E/AndroidRuntime(275): FATAL EXCEPTION: main
01-22 20:13:32.228: E/AndroidRuntime(275): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.flybase2/com.example.flybase2.addAppointment}: java.lang.RuntimeException: Binary XML file line #26: You must supply a layout_width attribute.
I have tried to change the scroll views width attribute (which i believe that error is pointing too) with no luck.
Here's my XML. Can anyone see what I'm doing wrong?:
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="84dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imgLink"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="#drawable/viewcon" />
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="75dp"
android:gravity="center"
android:text="Appointments"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="35sp" />
</LinearLayout>
\\ERROR: On width attribute
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/inputAppName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Type:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Time:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TimePicker
android:id="#+id/timePicker1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Time:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<DatePicker
android:id="#+id/datePicker1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comments:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/inputAppCom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set Appointment Date Alarm:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ToggleButton
android:id="#+id/toggleButton1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ToggleButton"
android:textOff="Alarm Off"
android:textOn="Alarm On" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Appointment"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/btnAddAppointment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add" />
</ScrollView>
</LinearLayout>
EDIT:
You can only set one child layout to a ScrollView. I don't know why it's showing you that you didn't set android:layout_width attribute, but your problem is definitely that you have multiple child views in your ScrollView.
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="84dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imgLink"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="#drawable/viewcon" />
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="75dp"
android:gravity="center"
android:text="Appointments"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="35sp" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/inputAppName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Type:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Time:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TimePicker
android:id="#+id/timePicker1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Time:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<DatePicker
android:id="#+id/datePicker1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comments:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/inputAppCom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set Appointment Date Alarm:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ToggleButton
android:id="#+id/toggleButton1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ToggleButton"
android:textOff="Alarm Off"
android:textOn="Alarm On" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Appointment"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/btnAddAppointment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add" />
</LinearLayout>
</ScrollView>
</LinearLayout>