Objects in XML Layout is overlapping on keyboard showing - java

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"

Related

App crashes when </ScrollView> put at end

full file follows: trying to have full scroll vertical in android device but putting scroll view at end of file produces crash
`<?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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.cancunsteve.aboutcancunsteve.MainActivity"
tools:showIn="#layout/activity_main">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
android:layout_alignParentStart="true"
android:layout_marginTop="56dp" />
<ImageView android:id="#+id/imageView"
android:layout_column="1"
android:background="#mipmap/lpussy"
android:contentDescription='android:ContentDescription="#string/desc"'
tools:ignore="HardcodedText"
android:layout_width="200dp"
android:layout_height="230dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="serving good people with special deals. "
android:id="#+id/text1"
android:layout_alignTop="#+id/imageView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#ffffff"
android:foreground="#05ffffff"
android:foregroundTint="#03ffffff"
android:textColor="#000000" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:text="Cancun, Playa del Carmen, Chichen Itza."
android:layout_below="#+id/text1"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:text="Holbox, Taxco, Palenque, Acapulco, Guanajuato,
Monterrey, Tenacatita, Mascota"
android:layout_below="#+id/editText2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButton"
android:layout_below="#+id/editText3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#mipmap/campa"
tools:ignore="ContentDescription"
android:layout_alignBottom="#+id/editText5" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/editText3"
android:text="thewebmaster#cancunsteve.com"
android:layout_below="#+id/editText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/editText"
android:layout_alignEnd="#+id/editText" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/editText4"
android:text=" 011 52 998 8873919"
android:layout_below="#+id/editText3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="42dp"
android:layout_marginStart="32dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText5"
android:text="be sure to visit us for discounts on your hotel bookings"
android:layout_below="#+id/editText4"
android:layout_toRightOf="#+id/scrollView"
android:layout_toEndOf="#+id/scrollView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="click buttons multiple times to change state"
android:id="#+id/textView2"
android:layout_below="#+id/imageButton" />
</RelativeLayout>`
when ScrollView added after Relative layout file won't open put it in brackets proceeded with backslash /
perhaps something I put in between the first and last ScrollView?
I noticed in the examples you show, scrollview appears in the beginning.
I reproduced your activity and after I removed the 2 backgrounds:
android:background="#mipmap/lpussy"
android:background="#mipmap/campa"
the activity does open fine.
Of course the scrollview is useless the way you use it, it must contain 1 container layout and inside that container all the views that you want to scroll.
Remove the backgrounds as well and try again. Maybe the problem is there.
<ScrollView 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="match_parent"
android:orientation="vertical" >
your views
</LinearLayout>
</ScrollView>
as scroll view can only contain a sinle child , so wrapping your views in a layout will work
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.cancunsteve.aboutcancunsteve.MainActivity"
tools:showIn="#layout/activity_main">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="56dp" >
<ImageView android:id="#+id/imageView"
android:layout_column="1"
android:background="#mipmap/lpussy"
android:contentDescription='android:ContentDescription="#string/desc"'
tools:ignore="HardcodedText"
android:layout_width="200dp"
android:layout_height="230dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="serving good people with special deals. "
android:id="#+id/text1"
android:layout_alignTop="#+id/imageView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#ffffff"
android:foreground="#05ffffff"
android:foregroundTint="#03ffffff"
android:textColor="#000000" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:text="Cancun, Playa del Carmen, Chichen Itza."
android:layout_below="#+id/text1"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:text="Holbox, Taxco, Palenque, Acapulco, Guanajuato,
Monterrey, Tenacatita, Mascota"
android:layout_below="#+id/editText2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButton"
android:layout_below="#+id/editText3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#mipmap/campa"
tools:ignore="ContentDescription"
android:layout_alignBottom="#+id/editText5" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/editText3"
android:text="thewebmaster#cancunsteve.com"
android:layout_below="#+id/editText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/editText"
android:layout_alignEnd="#+id/editText" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/editText4"
android:text=" 011 52 998 8873919"
android:layout_below="#+id/editText3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="42dp"
android:layout_marginStart="32dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText5"
android:text="be sure to visit us for discounts on your hotel bookings"
android:layout_below="#+id/editText4"
android:layout_toRightOf="#+id/scrollView"
android:layout_toEndOf="#+id/scrollView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="click buttons multiple times to change state"
android:id="#+id/textView2"
android:layout_below="#+id/imageButton" />
</RelativeLayout>
</ScrollView>
ScrollView must have a single child.
If you want your full layout to be scrollable then add at the top.
<?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:background="#color/background_grey"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imageView"
android:background="#ffffff"
android:foreground="#05ffffff"
android:foregroundTint="#03ffffff"
android:text="serving good people with special deals. "
android:textColor="#000000" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/text1"
android:text="Cancun, Playa del Carmen, Chichen Itza." />
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/editText2"
android:text="Holbox, Taxco, Palenque, Acapulco, Guanajuato,
Monterrey, Tenacatita, Mascota" />
<ImageButton
android:id="#+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editText5"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/editText3"
android:background="#mipmap/ic_launcher"
tools:ignore="ContentDescription" />
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/editText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/editText"
android:layout_below="#+id/editText"
android:ems="10"
android:inputType="textEmailAddress"
android:text="thewebmaster#cancunsteve.com" />
<EditText
android:id="#+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/editText3"
android:layout_marginLeft="42dp"
android:layout_marginStart="32dp"
android:ems="10"
android:inputType="phone"
android:text=" 011 52 998 8873919" />
<EditText
android:id="#+id/editText5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText4"
android:layout_toEndOf="#+id/scrollView"
android:layout_toRightOf="#+id/scrollView"
android:text="be sure to visit us for discounts on your hotel bookings" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageButton"
android:text="click buttons multiple times to change state" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
To make RelativeLayout scrollable, put it inside LinearLayout and
then put that LinearLayout inside ScrollView. This will solve the
problem.
Use the format shown below.
<ScrollView 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="match_parent"
android:orientation="vertical" >
<RelativeLayout
...
...
...
</RelativeLayout>
</LinearLayout>
</ScrollView>
UPDATE:
Step 1:
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
android:layout_alignParentStart="true"
android:layout_marginTop="56dp"> <---- LOOK HERE (remove /)
Step 2:
</ScrollView> <---- LOOK HERE (end the ScrollView before RelativeLayout)
</RelativeLayout>
As per your xml,
Its better to swap the top two element tags in your xml file.
So that yor RelativeLayout will become a child of ScrollView. and You dont have to edit your remaining layout elements
The result will be..
< ScrollView
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:id="#+id/scrollView"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.cancunsteve.aboutcancunsteve.MainActivity"
tools:showIn="#layout/activity_main">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginTop="56dp" >
And it should end like..
</RelativeLayout>
</ScrollView>
Addition:
You can replace the Relative Layout with a LinearLayout to get Rid of scrollView Errors...
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:orientation="vertical"
android:layout_marginTop="56dp" >
<ImageView android:id="#+id/imageView"
android:layout_column="1"
android:background="#ff0f"
android:contentDescription='android:ContentDescription="#string/desc"'
tools:ignore="HardcodedText"
android:layout_width="200dp"
android:layout_height="230dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="serving good people with special deals. "
android:id="#+id/text1"
android:layout_alignTop="#+id/imageView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#ffffff"
android:foreground="#05ffffff"
android:foregroundTint="#03ffffff"
android:textColor="#000000" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:text="Cancun, Playa del Carmen, Chichen Itza."
android:layout_below="#+id/text1"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:text="Holbox, Taxco, Palenque, Acapulco, Guanajuato,
Monterrey, Tenacatita, Mascota"
android:layout_below="#+id/editText2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButton"
android:layout_below="#+id/editText3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#f0f0"
tools:ignore="ContentDescription"
android:layout_alignBottom="#+id/editText5" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/editText3"
android:text="thewebmaster#cancunsteve.com"
android:layout_below="#+id/editText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/editText"
android:layout_alignEnd="#+id/editText" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/editText4"
android:text=" 011 52 998 8873919"
android:layout_below="#+id/editText3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="42dp"
android:layout_marginStart="32dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText5"
android:text="be sure to visit us for discounts on your hotel bookings"
android:layout_below="#+id/editText4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="click buttons multiple times to change state"
android:id="#+id/textView2"
android:layout_below="#+id/imageButton" />
</LinearLayout>
</ScrollView>

Achieving listview with bubble like badge on item type?

I'm trying to achieve a customized ListView with every group of ListView items of the same type, there should be a button/bubble badge hovering above the first item of this group. It should look like this:
If possible I'd love to know how to switch the main bubble on the toolbar to change when the group of item type has been scrolled up and reached it.
Try Using an Image Button
Add the image you want the button to hold in
android:src=" "
Example of a layout using Image Button.
<?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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.shakthivels.assignment_8.FormActivity"
android:id="#+id/rl"
>
<EditText
android:layout_width="120sp"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:hint="Name" />
<EditText
android:layout_width="100sp"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:layout_alignBottom="#+id/editText"
android:layout_centerHorizontal="true"
android:hint="Height"
android:inputType="numberDecimal"
android:layout_alignParentTop="true" />
<EditText
android:layout_width="120sp"
android:layout_height="wrap_content"
android:id="#+id/editText3"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:hint="Swag %"
android:inputType="number|numberDecimal"
android:layout_above="#+id/button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button"
android:layout_centerHorizontal="true"
android:onClick="onclickbutton"
android:layout_below="#+id/editText" />
<android.support.v7.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/view"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginTop="150sp"
android:clickable="true"
android:onClick="DisplayName"
android:contextClickable="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView4"
android:layout_below="#+id/button"
android:layout_toStartOf="#+id/editText3"
android:layout_alignParentEnd="true" />
<ImageButton
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#mipmap/ic_launcher"
android:id="#+id/imageButton"
android:layout_gravity="right|bottom"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/editText3"
android:onClick="RemoveFirst" />
</RelativeLayout>

Android studio setting layout up like this

I've tried everything I can think of but can't get this layout working. It's a ListView that list matches in a row.
Row one is first match, and next row is second match, and so on. I don't don't mind the green strokes and borders.
Is it even possible?
See the deisgn here:
Here's an example implementation, it does however use negative margins, to overlap the thing I called badge.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#cdcdcd"
android:gravity="center_vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/score"
android:layout_below="#+id/badge"
android:background="#color/white"
android:orientation="vertical"
android:padding="16dp"
android:showDividers="middle">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView 1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView 2"/>
</LinearLayout>
<TextView
android:id="#+id/score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:padding="16dp"
android:text="0 vs 7"
android:layout_below="#+id/badge"
android:textSize="32sp"
android:textStyle="bold"/>
<LinearLayout
android:layout_below="#+id/badge"
android:id="#+id/right_table"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/score"
android:background="#color/white"
android:orientation="vertical"
android:padding="16dp"
android:showDividers="middle">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView 1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView 2"/>
</LinearLayout>
<TextView
android:id="#+id/badge"
android:layout_toRightOf="#id/score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#0f0"
android:layout_marginLeft="-12dp"
android:layout_marginBottom="-8dp"
android:text="Badge"
/>
</RelativeLayout>
To alternate the background simply set the background in getView in your adapter.
You'll need a custom adapter that fills the ListView (better use RecyclerView & an Adapter with ViehHolder), this row layout is taken from my own project, not exactly what you requested, but you'll get the idea. Just comment for further information.
<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="wrap_content"
>
<TextView
android:id="#+id/textV_player1"
android:text="player1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="40dp"
android:layout_marginEnd="40dp"
android:textSize="20sp"
android:paddingTop="15dp"
android:gravity="end"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/textV_vs"
android:layout_toStartOf="#+id/textV_vs" />
<TextView
android:id="#+id/textV_player2"
android:text="player2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingTop="15dp"
android:layout_alignBottom="#+id/textV_vs"
android:layout_toRightOf="#+id/textV_vs"
android:layout_toEndOf="#+id/textV_vs" />
<TextView
android:id="#+id/textV_vs"
android:text="vs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="40dp"
android:layout_marginEnd="40dp"
android:textSize="20sp"
android:layout_above="#+id/textV_points1"
android:layout_centerHorizontal="true" />
<TextView
android:id="#+id/textV_points1"
android:text="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingTop="3dp"
android:paddingBottom="15dp"
android:layout_below="#+id/textV_player1"
android:layout_alignRight="#+id/textV_player1"
android:layout_alignEnd="#+id/textV_player1" />
<TextView
android:id="#+id/textV_points2"
android:text="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingTop="3dp"
android:paddingBottom="15dp"
android:layout_below="#+id/textV_player2"
android:layout_alignLeft="#+id/textV_player2"
android:layout_alignStart="#+id/textV_player2" />
<TextView
android:id="#+id/textV_vspoints"
android:text=":"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingBottom="15dp"
android:layout_below="#id/textV_vs"
android:layout_centerHorizontal="true" />
</RelativeLayout>

RelativeLayout inside Scrollview in android

I am stuck in a problem and not able find any solution. This problem may sound very naive but I am really unable to figure out the exact cause. I have a ScrollView ans inside that I have a RelativeLayout. But my RelativeLayout is not scrolling irrespective of the content. I have followed https://stackoverflow.com/relativelayout-with-scrollview-not-scrolling and https://stackoverflow.com/relativelayout-inside-scrollview-not-working and few more also. Please check where I am doing wrong. Thanks.
xml code :
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity"
android:scrollbars="vertical"
android:background="#drawable/cover_image"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/cover_img_labels"
android:layout_width="300dp"
android:layout_height="105dp"
android:background="#drawable/cover_image_labels"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<RelativeLayout
android:id="#+id/rl_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:layout_below="#+id/cover_img_labels"
android:layout_centerHorizontal="true">
<EditText
android:id="#+id/et_login_userName"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:background="#drawable/edittext_style"
android:textColor="#7593B0"
android:singleLine="true"
android:paddingLeft="10dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:hint="#string/hint_login_user" />
<EditText
android:id="#+id/et_login_password"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/et_login_userName"
android:textColor="#7593B0"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:background="#drawable/edittext_style"
android:singleLine="true"
android:hint="#string/hint_login_password"
android:imeOptions="actionDone"
android:inputType="textPassword" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="100dp"
android:orientation="horizontal"
android:id="#+id/linearLayout">
<Button
android:id="#+id/bt_login_submit"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="#string/text_login_submit"
android:layout_marginRight="2dp"
android:textColor="#android:color/white"
android:background="#drawable/button_drawable"
android:layout_below="#+id/et_login_password" />
<Button
android:id="#+id/bt_register_submit"
android:layout_width="0dp"
android:layout_weight="1"
android:background="#drawable/button_drawable"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:textColor="#android:color/white"
android:text="Register your card" />
</LinearLayout>
<ProgressBar
android:id="#+id/pb_login_progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:visibility="gone" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forgot Password"
android:id="#+id/bt_forgot_password"
android:textColor="#color/pink"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:layout_marginTop="5dp"
android:background="#drawable/forgot_button_drawable"
android:layout_below="#+id/linearLayout"
android:layout_centerHorizontal="true" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_below="#+id/bt_forgot_password"
android:gravity="center"
android:id="#+id/lll"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button2"
android:layout_alignRight="#+id/button"
android:layout_alignEnd="#+id/button" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
I just run your code, it cannot scroll because height of relative layout not enough. You only scroll when height of ScrollView smaller than height of ScrollView's child.
You can change RelativeLayout's height from wrap_content to 1000dp to test scroll.

Set object correctly in a layout

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..

Categories