A scroll view can have only one child Android XML file - java

So, I want to have a scrollview on my layout. I did this and got a scroll view can only have one child :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="95dip"
android:layout_marginRight="5dip"
android:layout_marginTop="10dip"
android:text="Latitude: "
android:textSize="15dip" >
</TextView>
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="unknown"
android:textSize="15dip" >
</TextView>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="90dip"
android:layout_marginRight="5dip"
android:text="Longitute: "
android:textSize="15dip" >
</TextView>
<TextView
android:id="#+id/TextView04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="unknown"
android:textSize="15dip" >
</TextView>
</LinearLayout>
<Button
android:id="#+id/button1"
android:layout_width="130dip"
android:layout_height="30dip"
android:layout_marginLeft="95dip"
android:layout_marginTop="10dip"
android:text="Find Coordinates"
android:textSize="10dip" />
<EditText
android:id="#+id/editTextName"
android:layout_width="264dp"
android:layout_height="wrap_content"
android:layout_marginLeft="25dip"
android:layout_marginTop="20dip"
android:ems="10"
android:hint="Enter Location Name"
android:textSize="10dip" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editTextPhone"
android:layout_width="264dp"
android:layout_height="wrap_content"
android:layout_marginLeft="25dip"
android:layout_marginTop="0dip"
android:ems="10"
android:hint="Enter Phone Number"
android:textSize="10dip" />
<EditText
android:id="#+id/editTextEmail"
android:layout_width="264dp"
android:layout_height="wrap_content"
android:layout_marginLeft="25dip"
android:ems="10"
android:hint="Enter Email"
android:textSize="10dip" />
<EditText
android:id="#+id/editTextDesc"
android:layout_width="264dp"
android:layout_height="wrap_content"
android:layout_marginLeft="25dip"
android:ems="10"
android:hint="Enter Description"
android:textSize="10dip" />
<EditText
android:id="#+id/editTextFlowers"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginLeft="50dip"
android:hint="Flowers"
android:ems="10"
android:textSize="10dip" />
<EditText
android:id="#+id/editTextPlants"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginLeft="180dip"
android:layout_marginTop="-35dip"
android:hint="Plants"
android:ems="10"
android:textSize="10dip" />
<EditText
android:id="#+id/editTextFruit"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginLeft="50dip"
android:hint="Fruit"
android:ems="10"
android:textSize="10dip" />
<EditText
android:id="#+id/editTextVeggies"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginLeft="180dip"
android:layout_marginTop="-35dip"
android:hint="Veggies"
android:ems="10"
android:textSize="10dip" />
<EditText
android:id="#+id/editTextSun"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginLeft="115dip"
android:ems="10"
android:hint="Sunday"
android:textSize="10dip" />
<Button
android:id="#+id/saveLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="90dip"
android:layout_marginTop="10dip"
android:text="Save Location" />
<Button
android:id="#+id/seeAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="120dip"
android:text="See all" />
</ScrollView>
Then, following the answer to this question
java.lang.IllegalStateException: ScrollView can host only one direct child
I did this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="95dip"
android:layout_marginRight="5dip"
android:layout_marginTop="10dip"
android:text="Latitude: "
android:textSize="15dip" >
</TextView>
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="unknown"
android:textSize="15dip" >
</TextView>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation = "vertical" >
<TextView
android:id="#+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="90dip"
android:layout_marginRight="5dip"
android:text="Longitute: "
android:textSize="15dip" >
</TextView>
<TextView
android:id="#+id/TextView04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="unknown"
android:textSize="15dip" >
</TextView>
</LinearLayout>
<Button
android:id="#+id/button1"
android:layout_width="130dip"
android:layout_height="30dip"
android:layout_marginLeft="95dip"
android:layout_marginTop="10dip"
android:text="Find Coordinates"
android:textSize="10dip" />
<EditText
android:id="#+id/editTextName"
android:layout_width="264dp"
android:layout_height="wrap_content"
android:layout_marginLeft="25dip"
android:layout_marginTop="20dip"
android:ems="10"
android:hint="Enter Location Name"
android:textSize="10dip" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editTextPhone"
android:layout_width="264dp"
android:layout_height="wrap_content"
android:layout_marginLeft="25dip"
android:layout_marginTop="0dip"
android:ems="10"
android:hint="Enter Phone Number"
android:textSize="10dip" />
<EditText
android:id="#+id/editTextEmail"
android:layout_width="264dp"
android:layout_height="wrap_content"
android:layout_marginLeft="25dip"
android:ems="10"
android:hint="Enter Email"
android:textSize="10dip" />
<EditText
android:id="#+id/editTextDesc"
android:layout_width="264dp"
android:layout_height="wrap_content"
android:layout_marginLeft="25dip"
android:ems="10"
android:hint="Enter Description"
android:textSize="10dip" />
<EditText
android:id="#+id/editTextFlowers"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginLeft="50dip"
android:hint="Flowers"
android:ems="10"
android:textSize="10dip" />
<EditText
android:id="#+id/editTextPlants"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginLeft="180dip"
android:layout_marginTop="-35dip"
android:hint="Plants"
android:ems="10"
android:textSize="10dip" />
<EditText
android:id="#+id/editTextFruit"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginLeft="50dip"
android:hint="Fruit"
android:ems="10"
android:textSize="10dip" />
<EditText
android:id="#+id/editTextVeggies"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginLeft="180dip"
android:layout_marginTop="-35dip"
android:hint="Veggies"
android:ems="10"
android:textSize="10dip" />
<EditText
android:id="#+id/editTextSun"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginLeft="115dip"
android:ems="10"
android:hint="Sunday"
android:textSize="10dip" />
<Button
android:id="#+id/saveLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="90dip"
android:layout_marginTop="10dip"
android:text="Save Location" />
<Button
android:id="#+id/seeAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="120dip"
android:text="See all" />
</ScrollView>
but still no luck. Any ideas? Thanks.

The key here is
ScrollView can host only one direct child
"direct" being the keyword. So you can have
<ScrollView
...>
<LinearLayout>
....
<!-- you can have as many Views in here as you want -->
</LinearLayout>
</ScrollView>
So, the LinearLayout in the above example would be your one direct child. And that child can have as many children as you want. Which means you can have all of your other LinearLayouts inside that first one. But you can't have more than one on the same hierarchical level.

Related

Android App is not fitting to different screen sizes

I am almost done with this app, but now that I test it on different devices, all the elements aren't fitting the same way. How do I make it scalable to fit different screens? Or do i have to remake the entire UI from scratch?
XML File
<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="com.example.rugpacalc.MainActivity$PlaceholderFragment" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView1"
android:layout_marginLeft="35dp"
android:layout_toRightOf="#+id/textView1"
android:text="Credit " />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView2"
android:layout_alignBottom="#+id/textView2"
android:layout_marginLeft="27dp"
android:layout_toRightOf="#+id/textView2"
android:text="Grade " />
<EditText
android:id="#+id/Course1"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText3"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/editText2"
android:ems="10" />
<EditText
android:id="#+id/editText4"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/editText3"
android:ems="10" />
<EditText
android:id="#+id/editText5"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/editText4"
android:ems="10" />
<EditText
android:id="#+id/editText6"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/editText5"
android:ems="10" />
<EditText
android:id="#+id/editText8"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText2"
android:layout_alignBottom="#+id/editText2"
android:layout_alignLeft="#+id/editText7"
android:ems="10"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/editText9"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText3"
android:layout_alignBottom="#+id/editText3"
android:layout_alignLeft="#+id/editText8"
android:ems="10"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/editText10"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText4"
android:layout_alignBottom="#+id/editText4"
android:layout_alignLeft="#+id/editText9"
android:ems="10"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/editText11"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText5"
android:layout_alignBottom="#+id/editText5"
android:layout_alignLeft="#+id/editText10"
android:ems="10"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/editText12"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText11"
android:layout_below="#+id/editText5"
android:ems="10"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/editText13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView3"
android:layout_alignRight="#+id/textView3"
android:layout_below="#+id/textView2"
android:ems="10" />
<EditText
android:id="#+id/editText14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText8"
android:layout_alignBottom="#+id/editText8"
android:layout_alignLeft="#+id/editText13"
android:layout_alignRight="#+id/editText13"
android:ems="10" />
<EditText
android:id="#+id/editText15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText9"
android:layout_alignBottom="#+id/editText9"
android:layout_alignLeft="#+id/editText14"
android:layout_alignRight="#+id/editText14"
android:ems="10" />
<EditText
android:id="#+id/editText16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText10"
android:layout_alignBottom="#+id/editText10"
android:layout_alignLeft="#+id/editText15"
android:layout_alignRight="#+id/editText15"
android:ems="10" />
<EditText
android:id="#+id/editText17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText11"
android:layout_alignBottom="#+id/editText11"
android:layout_alignLeft="#+id/editText16"
android:layout_alignRight="#+id/editText16"
android:ems="10" />
<EditText
android:id="#+id/editText18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText12"
android:layout_alignBottom="#+id/editText12"
android:layout_alignLeft="#+id/editText17"
android:layout_alignRight="#+id/editText17"
android:ems="10" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editText13"
android:layout_alignParentRight="true"
android:text="" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editText14"
android:layout_alignParentRight="true"
android:text="" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/editText16"
android:layout_alignParentRight="true"
android:text="" />
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editText16"
android:layout_alignParentRight="true"
android:text="" />
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editText17"
android:layout_alignParentRight="true"
android:text="" />
<TextView
android:id="#+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editText18"
android:layout_alignParentRight="true"
android:text="" />
<EditText
android:id="#+id/editText7"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_above="#+id/editText8"
android:layout_toRightOf="#+id/Course1"
android:ems="10"
android:hint=""
android:inputType="number|numberDecimal" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView3"
android:layout_alignParentRight="true"
android:text="CreditEd" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView11"
android:layout_below="#+id/textView11"
android:text="Total Credit Pts Earned:" />
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView12"
android:layout_below="#+id/textView12"
android:text="Cumulative GPA:" />
<TextView
android:id="#+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView13"
android:layout_below="#+id/textView13"
android:layout_marginTop="14dp"
android:text="Semester Credits" />
<TextView
android:id="#+id/textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView14"
android:text="Semester Credit Points:" />
<TextView
android:id="#+id/textView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView15"
android:layout_below="#+id/textView15"
android:text="Semester GPA:" />
<TextView
android:id="#+id/textView17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView11"
android:layout_toLeftOf="#+id/textView4"
android:text="" />
<TextView
android:id="#+id/textView18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView12"
android:layout_alignBottom="#+id/textView12"
android:layout_alignRight="#+id/textView17"
android:text="" />
<TextView
android:id="#+id/textView19"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/textView18"
android:layout_below="#+id/textView18"
android:text="" />
<TextView
android:id="#+id/textView20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView15"
android:layout_alignLeft="#+id/textView19"
android:text="" />
<TextView
android:id="#+id/textView21"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView15"
android:layout_alignBottom="#+id/textView15"
android:layout_alignRight="#+id/textView20"
android:text="" />
<TextView
android:id="#+id/textView22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/textView21"
android:layout_below="#+id/textView21"
android:text="" />
<TextView
android:id="#+id/tv23"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView17"
android:layout_toRightOf="#+id/editText18"
android:text="TextView" />
<TextView
android:id="#+id/tv24"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView18"
android:layout_alignBottom="#+id/textView18"
android:layout_alignLeft="#+id/tv23"
android:text="TextView" />
<TextView
android:id="#+id/tv25"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView14"
android:layout_alignLeft="#+id/tv24"
android:text="TextView" />
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView15"
android:layout_below="#+id/button2"
android:text="Total Credits Completed:" />
<Button
android:id="#+id/button1"
android:layout_width="60dp"
android:layout_height="35dp"
android:layout_alignLeft="#+id/button2"
android:layout_alignRight="#+id/textView08"
android:layout_below="#+id/editText6"
android:layout_marginTop="70dp"
android:text="Calculate" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignLeft="#+id/textView11"
android:layout_alignRight="#+id/textView08"
android:layout_below="#+id/button1"
android:text="Next" />
<EditText
android:id="#+id/EditText01"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText6"
android:layout_below="#+id/editText6"
android:ems="10" />
<EditText
android:id="#+id/EditText02"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button1"
android:layout_below="#+id/EditText01"
android:ems="10" />
<EditText
android:id="#+id/EditText05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/EditText04"
android:layout_alignLeft="#+id/editText18"
android:layout_alignRight="#+id/editText18"
android:ems="10" />
<EditText
android:id="#+id/EditText06"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/EditText05"
android:layout_alignRight="#+id/EditText05"
android:layout_below="#+id/EditText03"
android:ems="10" />
<TextView
android:id="#+id/textView07"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/EditText05"
android:layout_alignParentRight="true" />
<TextView
android:id="#+id/textView08"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/EditText06"
android:layout_alignParentRight="true" />
<EditText
android:id="#+id/editText2"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_below="#+id/Course1"
android:layout_toLeftOf="#+id/editText8"
android:ems="10" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/Course1"
android:layout_alignParentTop="true"
android:layout_marginTop="42dp"
android:text="Course" />
<EditText
android:id="#+id/EditText03"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_above="#+id/EditText02"
android:layout_toRightOf="#+id/EditText01"
android:ems="10"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/EditText04"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_below="#+id/EditText01"
android:layout_toRightOf="#+id/EditText01"
android:ems="10"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignLeft="#+id/textView1"
android:layout_alignParentTop="true"
android:ems="10"
android:hint="Enter Semester" />
</RelativeLayout>
The answer would be too large... If you mean to keep the proportions you can use weight rather than dps. Anyway I recomend you to read this article:
http://developer.android.com/guide/practices/screens_support.html

EditText filed wont Behave accordingly

I have 9 Edittext fields to work with. But their is a problem. I set the Edittext fields accordingly but when I run this application on emulator the fields reset them self automatically ( They are not remain at the place where i set them ).And when i run the apk on my mobile (sumsang y S 5360) they look even worse. Here is a 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="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/zmal"
tools:ignore="ExtraText,TextFields" >
<TextView
android:id="#+id/showz"
android:layout_width="200dip"
android:layout_height="30dip"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:fontFamily="bold"
android:textColor="#fefdfd"
android:textSize="20sp" />
<Button
android:id="#+id/calc"
android:layout_width="80dip"
android:layout_height="45dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#drawable/calbu"
android:paddingBottom="10dp"
android:paddingLeft="5dp" />
<EditText
android:id="#+id/zktmal3"
android:layout_width="40dip"
android:layout_height="20dip"
android:layout_alignParentRight="true"
android:layout_below="#+id/zktmal2"
android:layout_marginTop="16dp"
android:ems="10"
android:padding="3dp"
android:inputType="number"
android:textSize="12sp" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/zktmal5"
android:layout_width="40dip"
android:layout_height="20dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:ems="10"
android:padding="3dp"
android:inputType="number"
android:textSize="12sp" />
<EditText
android:id="#+id/zktmal8"
android:layout_width="40dip"
android:layout_height="20dip"
android:layout_alignParentRight="true"
android:layout_below="#+id/zktmal6"
android:layout_marginTop="27dp"
android:ems="10"
android:padding="3dp"
android:inputType="number"
android:textSize="12sp" />
<EditText
android:id="#+id/zktmal9"
android:layout_width="40dip"
android:layout_height="20dip"
android:layout_alignParentRight="true"
android:layout_below="#+id/zktmal8"
android:layout_marginTop="21dp"
android:ems="10"
android:padding="3dp"
android:inputType="number"
android:textSize="12sp"/>
<EditText
android:id="#+id/zktmal10"
android:layout_width="40dip"
android:layout_height="20dip"
android:layout_above="#+id/calc"
android:layout_alignParentRight="true"
android:layout_marginBottom="15dp"
android:ems="10"
android:padding="3dp"
android:inputType="number"
android:textSize="12sp" />
<EditText
android:id="#+id/zktmal1"
android:layout_width="40dip"
android:layout_height="20dip"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="48dp"
android:ems="10"
android:inputType="number"
android:padding="3dp"
android:textSize="12sp" />
<EditText
android:id="#+id/zktmal4"
android:layout_width="40dip"
android:layout_height="20dip"
android:layout_above="#+id/zktmal5"
android:layout_alignParentRight="true"
android:layout_marginBottom="24dp"
android:ems="10"
android:inputType="number"
android:padding="3dp"
android:textSize="12sp" />
<EditText
android:id="#+id/zktmal2"
android:layout_width="40dip"
android:layout_height="20dip"
android:layout_alignParentRight="true"
android:layout_below="#+id/zktmal1"
android:ems="10"
android:inputType="number"
android:padding="3dp"
android:textSize="12sp" />
<EditText
android:id="#+id/zktmal6"
android:layout_width="40dip"
android:layout_height="20dip"
android:layout_alignParentRight="true"
android:layout_below="#+id/zktmal5"
android:ems="10"
android:inputType="number"
android:padding="3dp"
android:textSize="12sp" />
</RelativeLayout
Here is screenshot
http://postimg.org/image/6yf04lx6h/
Use linearlayout and orientation:horizontal for each row:
And use a general relative layout for scroll view.
like this
<ScroolView>
<RelativeLayout>
<LinearLayout />
<LinearLAyout />
<LinearLayout />
.
.
</RelativeLAyout>
<ScrollView>
You don't show how you layout the TextViews in your XML post but it is clear that they are very verbose. When you have such a long TextView to caption an EditText, it would be better to just put the EditText on the next line.
If I were you, I would just have a scrolling layout like so:
<ScrollView>
<TextView android:id="#+id/label1"/>
<EditText> android:id="#+id/edit1"/>
...
...
<TextView android:id="#+id/labelN"/>
<EditText android:id="#+id/editN"/>
</ScrollView>

Adjusting the gridview and roe of buttons

I am trying to adjust the space between grid view and buttons
I have posted figure
I am trying to attain that
XML
<?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" >
<!-- Top navigation bar for Restaurant Description Page -->
<TableRow
android:id="#+id/tableRow6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2sp" >
<RelativeLayout
android:id="#+id/TopNavigationBarRestaurantDesc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#726E6D" >
<!-- Back Button -->
<Button
android:id="#+id/TopNavigationBarRestaurantDescActivityBackButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="BACK"
android:textColor="#android:color/white"
android:textSize="12sp" />
<!-- Restaurant Description page name -->
<TextView
android:id="#+id/TopNavigationBarRestaurantDescActivityName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="TextView"
android:textColor="#android:color/white"
android:textSize="18sp"
android:textStyle="bold" />
<!-- Restaurant Description page Image -->
<ImageView
android:id="#+id/TopNavigationBarRestaurantDescActivityImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2sp" >
<TextView
android:id="#+id/RestaurantTimingsID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Timings"
android:textStyle="bold" />
</TableRow>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp" >
</LinearLayout>
<TableRow
android:id="#+id/BuyReservedButtonRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="2sp" >
<Button
android:id="#+id/BuyButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/buy_button_shape"
android:paddingBottom="13dp"
android:paddingLeft="16dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Buy"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6sp" />
<Button
android:id="#+id/ReservedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/reserverd_button_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Reserve"
android:textColor="#android:color/white" />
</TableRow>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableRow
android:id="#+id/DescriptionTitleRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2sp" >
<GridView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="80dp"
android:gravity="center"
android:numColumns="3"
android:scrollbars="horizontal"
android:stretchMode="spacingWidthUniform" >
</GridView>
</TableRow>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp" >
</LinearLayout>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal" >
<Button
android:id="#+id/RestaurantDescriptionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Description"
android:textColor="#android:color/white"
android:textSize="11sp" />
<Button
android:id="#+id/RestaurantLocationButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Location"
android:textColor="#android:color/white"
android:textSize="11sp" />
<Button
android:id="#+id/RestaurantPhotosButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Photos"
android:textColor="#android:color/white"
android:textSize="11sp" />
<Button
android:id="#+id/RestaurantFriendsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Friends"
android:textColor="#android:color/white"
android:textSize="11sp" />
</LinearLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow7"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal" >
<Button
android:id="#+id/RestaurantSearchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_square_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Search"
android:textColor="#android:color/white"
android:textSize="11sp" />
<Button
android:id="#+id/RestaurantFeaturedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_square_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Featured"
android:textColor="#android:color/white"
android:textSize="11sp" />
<Button
android:id="#+id/RestaurantDealsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_square_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Deals"
android:textColor="#android:color/white"
android:textSize="11sp" />
<Button
android:id="#+id/RestaurantInviteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_square_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Invite"
android:textColor="#android:color/white"
android:textSize="11sp" />
<Button
android:id="#+id/RestaurantAccountButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_square_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Account"
android:textColor="#android:color/white"
android:textSize="11sp" />
</LinearLayout>
</TableRow>
</LinearLayout>
</LinearLayout>
How to remove the space between the grid view and below row of buttons
How to remove the space below gridview
Try below segment of code, replace with your code and pls check once.
<TableRow
android:id="#+id/DescriptionTitleRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="2sp" >
<GridView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="80dp"
android:gravity="center"
android:numColumns="3"
android:scrollbars="horizontal"
android:stretchMode="spacingWidthUniform" >
</GridView>
</TableRow>

Ensure the EditText is directly below the label using LinearLayout

I have the following XML code (partial for this example purposes):
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="0dp"
android:paddingRight="0dp" >
<RadioGroup
android:id="#+id/rgVehicle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.5" >
<RadioButton
android:id="#+id/rbCar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Car" />
<RadioButton
android:id="#+id/rbTruck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Truck" />
<RadioButton
android:id="#+id/rbCycle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Motorcycle" />
</RadioGroup>
<EditText
android:id="#+id/etToll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal"
android:layout_weight=".5" />
</LinearLayout>
For smaller screen like Galaxy Nexus and Nexus One the layout comes out like this:
How do I fix it so the EditText is directly below the #6 label as shown below (no matter what size the screen is):
There you go:
<?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="wrap_content" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5. Vehicle type"
android:textAppearance="?android:attr/textAppearanceLarge" />
<RadioGroup
android:id="#+id/rgVehicle"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/rbCar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Car" />
<RadioButton
android:id="#+id/rbTruck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Truck" />
<RadioButton
android:id="#+id/rbCycle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Motorcycle" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6. Total amount"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/etToll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal" />
</LinearLayout>
</LinearLayout>
Use something like this:
<tablelayout>
<tablerow android:layout_weightsum="2">
<textview android:layout_weight="1" android:text="4">
<textview android:layout_weight="1" android:text="6">
</tablerow>
<tablerow android:layout_weightsum="2">
<radiogroup android:layout_weight="1">
<!-- add radio buttons here -->
</radiogroup>
<edittext android:layout_weight="1" >
</tablerow>
</tablelayout>

Android table layout starts from the edge of the phone

I'm using table layout to show some data but the table starts from the edge of the phone from left to right. How do i do if i want the entire table at the center and some space on right and left. Please advice. Below is my code.
Code
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF" >
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="2" >
<LinearLayout android:gravity="left" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="150dp"
android:layout_height="50dp"
android:src="#drawable/ezwaybill" />
</LinearLayout>
<TableRow
android:layout_width="fill_parent"
android:padding="2dip" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="150dp"
android:layout_height="50dp"
android:src="#drawable/van" />
</TableRow>
<LinearLayout android:gravity="center" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SENDER"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="22sp" />
</LinearLayout>
<TableRow
android:layout_width="fill_parent"
android:padding="2dip" >
<TextView
android:id="#+id/textView1"
android:text="Account"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15sp" />
<EditText
android:id="#+id/editText1"
android:layout_span="2"
android:editable="false"
android:text="0001"
android:textSize="15sp" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:padding="2dip" >
<TextView
android:id="#+id/textView3"
android:text="Tel"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15sp" />
<EditText
android:id="#+id/editText2"
android:layout_span="2"
android:editable="false"
android:text="01111022408615"
android:textSize="15sp" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:padding="2dip" >
<TextView
android:id="#+id/textView5"
android:text="Add"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15sp" />
<EditText
android:id="#+id/editText3"
android:layout_span="2"
android:editable="false"
android:text="No. 7, Ferrers Park"
android:textSize="15sp" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:padding="2dip" >
<TextView
android:id="#+id/textView5"
android:text="Country"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15sp" />
<EditText
android:id="#+id/editText4"
android:layout_span="2"
android:editable="false"
android:text="Malaysia"
android:textSize="15sp" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:padding="2dip" >
<TextView
android:id="#+id/textView6"
android:text="Postcode "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15sp" />
<EditText
android:id="#+id/editText5"
android:layout_span="2"
android:editable="false"
android:text="44800"
android:textSize="15sp" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:padding="2dip" >
<TextView
android:id="#+id/textView7"
android:text="Email"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15sp" />
<EditText
android:id="#+id/editText6"
android:layout_span="2"
android:editable="false"
android:text="customer#domain.com"
android:textSize="15sp" />
</TableRow>
<TextView
android:layout_width="10dp"
android:layout_height="10dp" />
</TableLayout>
</ScrollView>
use this code it look like as shown in image
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000" >
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="2"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_gravity="center">
<LinearLayout android:gravity="left" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="150dp"
android:layout_height="50dp"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<TableRow
android:layout_width="fill_parent"
android:padding="2dip" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="150dp"
android:layout_height="50dp"
android:src="#drawable/ic_launcher" />
</TableRow>
<LinearLayout android:gravity="center" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SENDER"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="22sp" />
</LinearLayout>
<TableRow
android:layout_width="fill_parent"
android:padding="2dip" >
<TextView
android:id="#+id/textView1"
android:text="Account"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15sp" />
<EditText
android:id="#+id/editText1"
android:layout_span="2"
android:editable="false"
android:text="0001"
android:textSize="15sp" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:padding="2dip" >
<TextView
android:id="#+id/textView3"
android:text="Tel"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15sp" />
<EditText
android:id="#+id/editText2"
android:layout_span="2"
android:editable="false"
android:text="01111022408615"
android:textSize="15sp" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:padding="2dip" >
<TextView
android:id="#+id/textView5"
android:text="Add"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15sp" />
<EditText
android:id="#+id/editText3"
android:layout_span="2"
android:editable="false"
android:text="No. 7, Ferrers Park"
android:textSize="15sp" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:padding="2dip" >
<TextView
android:id="#+id/textView5"
android:text="Country"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15sp" />
<EditText
android:id="#+id/editText4"
android:layout_span="2"
android:editable="false"
android:text="Malaysia"
android:textSize="15sp" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:padding="2dip" >
<TextView
android:id="#+id/textView6"
android:text="Postcode "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15sp" />
<EditText
android:id="#+id/editText5"
android:layout_span="2"
android:editable="false"
android:text="44800"
android:textSize="15sp" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:padding="2dip" >
<TextView
android:id="#+id/textView7"
android:text="Email"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15sp" />
<EditText
android:id="#+id/editText6"
android:layout_span="2"
android:editable="false"
android:text="customer#domain.com"
android:textSize="15sp" />
</TableRow>
<TextView
android:layout_width="10dp"
android:layout_height="10dp" />
</TableLayout>
</ScrollView>
Give your main View a Size and set android:layout_gravity="center". (Not sure if this works with Views). So they dont fill the Parent.
Else just give it a
android:layout_marginLeft="150dp"
android:layout_marginRight="150dp"
for example.
best regards

Categories

Resources