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
Related
I'm trying to display information contained on a json with this code
<?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"
tools:context=".MarkerActivity">
<Button
android:id="#+id/button"
style="#android:style/Widget.Material.Button.Small"
android:layout_width="34dp"
android:layout_height="38dp"
android:layout_alignParentEnd="true"
android:layout_alignTop="#+id/textView"
android:layout_marginEnd="36dp"
android:layout_marginTop="-1dp"
android:text="+" />
<TextView
android:id="#+id/textView2"
android:layout_width="115dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="30dp"
android:layout_marginTop="149dp"
android:text="Status"
android:textSize="18sp"
android:textStyle="bold"
tools:text="Status" />
<TextView
android:id="#+id/mytextview"
android:layout_width="282dp"
android:layout_height="79dp"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="15dp"
android:layout_marginTop="27dp"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView" />
<ImageView
android:id="#+id/imageView"
android:layout_width="40dp"
android:layout_height="52dp"
android:layout_alignParentStart="true"
android:layout_alignTop="#+id/mytextview"
android:layout_marginStart="15dp"
android:src="#drawable/ic_mappin" />
<View
android:id="#+id/divider"
android:layout_width="match_parent"
android:layout_height="9dp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:background="?android:attr/listDivider" />
<View
android:id="#+id/divider2"
android:layout_width="match_parent"
android:layout_height="7dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="134dp"
android:background="?android:attr/listDivider" />
<ScrollView>
<TextView
android:id="#+id/textView"
android:layout_width="115dp"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/textView2"
android:layout_below="#+id/divider"
android:text="Comments"
android:textSize="18sp"
android:textStyle="bold"
tools:text="Comments" />
<TextView
android:id="#+id/jsonData1"
android:layout_width="155dp"
android:layout_height="83dp"
android:layout_alignStart="#+id/textView2"
android:layout_below="#+id/textView2"
android:layout_gravity="center_horizontal"
android:text="STATS"
android:textAppearance="#android:style/TextAppearance.Material.Small"
android:textSize="16sp" />
<TextView
android:id="#+id/jsonData2"
android:layout_width="157dp"
android:layout_height="117dp"
android:layout_alignStart="#+id/textView2"
android:layout_below="#+id/textView"
android:layout_gravity="center_horizontal"
android:text="COMMENTS"
android:textAppearance="#android:style/TextAppearance.Material.Small"
android:textSize="16sp" />
</ScrollView>
</RelativeLayout>
I need a scrollable view, due the fact that my json file could contain many entries and could fill all the space on the display.
With this code my program crash. Any idea how to solve it? I tried in many ways but always the same situation
ScrollView needs to have one child, so wrap your 3 TextViews in a LinearLayout layout and set it's height to wrap_content
ScrollView=>LinearLayout=>Textviews
ScrollView can have only one child but you put 3 child in scrollView. thats why your app is crash.
You need to put all child (all three textView) in one ViewGroup. then your app will run correctly. here you can see
<?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"
tools:context=".MarkerActivity">
<Button
android:id="#+id/button"
style="#android:style/Widget.Material.Button.Small"
android:layout_width="34dp"
android:layout_height="38dp"
android:layout_alignParentEnd="true"
android:layout_alignTop="#+id/textView"
android:layout_marginEnd="36dp"
android:layout_marginTop="-1dp"
android:text="+" />
<TextView
android:id="#+id/textView2"
android:layout_width="115dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="30dp"
android:layout_marginTop="149dp"
android:text="Status"
android:textSize="18sp"
android:textStyle="bold"
tools:text="Status" />
<TextView
android:id="#+id/mytextview"
android:layout_width="282dp"
android:layout_height="79dp"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="15dp"
android:layout_marginTop="27dp"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView" />
<ImageView
android:id="#+id/imageView"
android:layout_width="40dp"
android:layout_height="52dp"
android:layout_alignParentStart="true"
android:layout_alignTop="#+id/mytextview"
android:layout_marginStart="15dp"
android:src="#drawable/ic_mappin" />
<View
android:id="#+id/divider"
android:layout_width="match_parent"
android:layout_height="9dp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:background="?android:attr/listDivider" />
<View
android:id="#+id/divider2"
android:layout_width="match_parent"
android:layout_height="7dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="134dp"
android:background="?android:attr/listDivider" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="115dp"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/textView2"
android:layout_below="#+id/divider"
android:text="Comments"
android:textSize="18sp"
android:textStyle="bold"
tools:text="Comments" />
<TextView
android:id="#+id/jsonData1"
android:layout_width="155dp"
android:layout_height="83dp"
android:layout_alignStart="#+id/textView2"
android:layout_below="#+id/textView2"
android:layout_gravity="center_horizontal"
android:text="STATS"
android:textAppearance="#android:style/TextAppearance.Material.Small"
android:textSize="16sp" />
<TextView
android:id="#+id/jsonData2"
android:layout_width="157dp"
android:layout_height="117dp"
android:layout_alignStart="#+id/textView2"
android:layout_below="#+id/textView"
android:layout_gravity="center_horizontal"
android:text="COMMENTS"
android:textSize="16sp"
android:textAppearance="#android:style/TextAppearance.Material.Small"
/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
I have a relative layout where i already aligned almost all elements like i want, but there are two elements at the right bottom(textView and the icon of forbiden photo), they are aligned related to the parent, the parent is not the photo.
I want to align those elements to the bottom of the image that i have:
here is a
expected results:
the rectangle is where i want the textView and the camera forbiden icon!
and here is the xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="142dp"
android:layout_gravity="center"
android:layout_margin="#dimen/card_margin"
android:elevation="3dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
card_view:cardCornerRadius="#dimen/card_specie_radius">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.example.afcosta.inesctec.pt.android.Helpers.NexusBoldTextView
android:id="#+id/Avaliation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/plantName"
android:layout_marginStart="92dp"
android:layout_marginTop="15dp"
android:text="Avalie a fotografia" />
<com.example.afcosta.inesctec.pt.android.Helpers.NexusBoldTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/plantPhoto"
android:textColor="#color/base"
android:layout_marginTop="4dp"
android:layout_toStartOf="#+id/cameraForbiden"
android:text="TextView" />
<ImageView
android:id="#+id/reportImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/color_cursor_white" />
<ImageView
android:id="#+id/plantPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginRight="16dp" />
<ImageView
android:id="#+id/userIcon"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_alignParentBottom="true"
android:layout_below="#id/plantPhoto"
android:src="#drawable/ic_user"
/>
<com.example.afcosta.inesctec.pt.android.Helpers.NexusBoldTextView
android:id="#+id/plantName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/plantPhoto"
android:textColor="#color/nephritis"
android:textSize="18sp" />
<ImageView
android:id="#+id/starIcon"
android:layout_width="23dp"
android:layout_height="23dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/plantName"
android:src="#drawable/ic_star"
android:layout_marginLeft="10dp"
/>
<ImageView
android:id="#+id/cameraForbiden"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_toRightOf="#+id/plantName"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_no_photos"
android:layout_below="#id/plantPhoto"
/>
<com.example.afcosta.inesctec.pt.android.Helpers.NexusBoldTextView
android:id="#+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/plantPhoto"
android:textColor="#color/base"
android:layout_marginEnd="29dp"
android:layout_marginTop="8dp"
android:layout_toEndOf="#+id/userIcon"
android:layout_toLeftOf="#+id/userIcon"
android:paddingLeft="10px"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Use following code:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/plantPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginRight="16dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_margin="5dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/userIcon"
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/ic_user"
/>
<com.example.afcosta.inesctec.pt.android.Helpers.NexusBoldTextView
android:id="#+id/plantName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/nephritis"
android:textSize="18sp" />
</LinearLayout>
</RelativeLayout>
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" />
This XML is for a ROW in a custom listview. It seems to have an Invisible FRAME, I can't seem to be able to get rid of it and make row fill parent.
I would like the end result to be nothing but Rows, and not able to see background of layer below.
Thank you for reading, XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#ff515152"
android:layout_alignParentTop="true"
android:id="#+id/relativeLayout"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:layout_width="140dp"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView2"
android:textSize="25dp"
android:textColor="#fffff7fd"
android:gravity="center_vertical|right"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/textView"
android:layout_toStartOf="#+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25dp"
android:textColor="#fffff7fd"
android:layout_gravity="center_horizontal"
android:text="AND"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:id="#+id/textView" />
<TextView
android:layout_width="140dp"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/group_name"
android:textSize="25dp"
android:textColor="#fffff7fd"
android:gravity="center_vertical|right"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/textView"
android:layout_toEndOf="#+id/textView" />
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffb7bcb5"
android:layout_below="#+id/relativeLayout"
android:layout_centerHorizontal="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView3"
android:layout_gravity="center_horizontal"
android:layout_alignParentLeft="false"
android:layout_marginLeft="0dp"
android:layout_alignParentTop="false"
android:layout_marginTop="0dp"
android:layout_centerHorizontal="true"
android:textSize="17dp"
android:textColor="#fffff7fd" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView4"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/textView3"
android:layout_toStartOf="#+id/textView3"
android:textSize="17dp"
android:textColor="#fffff7fd" />
</RelativeLayout>
</RelativeLayout>
I was trying to create a sign up form for my Android application
This is my XML code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<TextView
android:id="#+id/mynumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number +961"
android:textSize="20sp"
android:color="#android:color/white" />
<EditText
android:id="#+id/editTextNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Number"
android:textColor="#FFFFFF" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical" >
<Button
android:id="#+id/buttonCreateAccount"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="60dp"
android:background="#drawable/ic_create" />
</LinearLayout>
</LinearLayout>
If you notice the first LinearLayout has a horizontal orientation and gravity (I want both the textview and edit text to be next to each others)
After the first linear layout i want the create account button to come out
However it is showing up on the same line with the previous edit text and text view
Any idea if i should change in the settings of the second linear layout
Change it like this
<LinearLayout
android:gravity="center_horizontal"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<LinearLayout
android:gravity="center_vertical"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal">
<TextView
android:color="#android:color/white"
android:id="#+id/mynumber"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Number +961"
android:textSize="20sp" />
<EditText
android:hint="Number"
android:id="#+id/editTextNumber"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#FFFFFF" />
</LinearLayout>
<Button
android:background="#drawable/ic_create"
android:id="#+id/buttonCreateAccount"
android:layout_height="wrap_content"
android:layout_marginBottom="60dp"
android:layout_width="fill_parent" />
</LinearLayout>
Try Below Xml File
Use Relative layout Or One MAin LinearLayout with Vertical Orientation and in sub take Horizontal as you required.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<TextView
android:id="#+id/mynumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number +961"
android:textSize="20sp"
android:color="#android:color/white" />
<EditText
android:id="#+id/editTextNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Number"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal" >
<Button
android:id="#+id/buttonCreateAccount"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="60dp"
android:background="#drawable/ic_create" />
</LinearLayout>
</LinearLayout>
<?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="match_parent"
android:orientation="vertical"
android:background="#drawable/sign">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="1200dp">
<TableLayout
android:layout_marginTop="40dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Signup for Juju's"
android:textSize="35dp"
android:textColor="#f45"
android:textStyle="bold" />
<TableRow
android:weightSum="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_weight="5"
android:id="#+id/nametv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Name"
android:textSize="25dp"
android:textColor="#23f" />
<EditText
android:textSize="16dp"
android:layout_marginRight="5dp"
android:layout_weight="15"
android:id="#+id/name"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:hint="Enter your name" >
</EditText>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:weightSum="20"
android:layout_height="wrap_content" >
<TextView
android:layout_weight="5"
android:textColor="#23f"
android:id="#+id/emailtv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email"
android:textSize="25dp" />
<EditText
android:textSize="16dp"
android:layout_weight="15"
android:layout_marginRight="5dp"
android:id="#+id/email"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:hint="Enter E-mail" />
</TableRow>
<TableRow
android:weightSum="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_weight="5"
android:textColor="#23f"
android:id="#+id/phonetv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone"
android:textSize="25dp" />
<EditText
android:textSize="16dp"
android:layout_marginRight="5dp"
android:layout_weight="15"
android:id="#+id/phone"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:hint="Enter Phone Number" />
</TableRow>
<TableRow
android:weightSum="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_weight="5"
android:textColor="#23f"
android:id="#+id/addresstv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address"
android:textSize="25dp" />
<EditText
android:textSize="16dp"
android:layout_marginRight="5dp"
android:layout_weight="15"
android:id="#+id/address"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:hint="Enter Address" />
</TableRow>
<TableRow
android:weightSum="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_weight="5"
android:textColor="#23f"
android:id="#+id/usernametv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username"
android:textSize="25dp" />
<EditText
android:textSize="16dp"
android:layout_weight="15"
android:layout_marginRight="5dp"
android:id="#+id/username"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:hint="Username" />
</TableRow>
<TableRow
android:weightSum="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_weight="5"
android:textColor="#23f"
android:id="#+id/passwordtv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:textSize="25dp" />
<EditText
android:textSize="16dp"
android:layout_marginRight="5dp"
android:layout_weight="15"
android:id="#+id/password"
android:inputType="textPassword"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:hint="Password" />
</TableRow>
<TableRow
android:weightSum="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_weight="5"
android:textColor="#23f"
android:id="#+id/confirmtv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reenter"
android:textSize="25dp" />
<EditText
android:textSize="16dp"
android:layout_marginRight="5dp"
android:layout_weight="15"
android:inputType="textPassword"
android:id="#+id/confirm"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:hint="Confirm Password" />
</TableRow>
<CheckBox
android:id="#+id/view_password"
android:checked="false"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View Password"
android:textColor="#000"/>
<ImageView
android:clickable="true"
android:id="#+id/submit"
android:layout_gravity="center"
android:layout_width="122dp"
android:layout_height="74dp"
android:src="#drawable/button" />
</TableLayout>
</ScrollView>
</LinearLayout>
Change your layout type;
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
Definitely. What your are doing is encapsulating the second LinearLayout inside the first LinearLayout, that dictates a horizontal layout, ultimately resulting in horizontal positioning of all three components. Your hierarchy is as follows:
LinearLayout-Horizontal[TextView + EditText + LinearLayout-Vertical[Button]]
When supplying a LinearLayout with an orientation parameter, you're telling it to arrange all its children in that manner.
What I would recommend to you, to achieve the desired look is either:
Use a RelativeLayout (http://developer.android.com/guide/topics/ui/layout/relative.html) and position the elements in relation to each other and their parent.
Nest several LinearLayouts(not a recommended practice; here it wouldn't prove an issue but in larger and more complex layouts nesting too many such components may ultimately result in long rendering time for your view). This solution is pretty similar to what you have now and would work as follows:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="#+id/mynumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number +961"
android:textSize="20sp"
android:color="#android:color/white" />
<EditText
android:id="#+id/editTextNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Number"
android:textColor="#FFFFFF" />
</LinearLayout>
<Button
android:id="#+id/buttonCreateAccount"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="60dp"
android:background="#drawable/ic_create" />
</LinearLayout>
Here you tell your outer layout to position its children vertically, where one of its children is a LinearLayout that positions its children horizontally, resulting in:
[[TEXT][EDIT]]
[ BUTTON ]
Hope this helps.