My app front page is not showing anything except the heading - android

The Following Code is From MainActivity.xml file
Only the Heading "G.K. Quiz" is appearing on the app.
It's just the same 10 questions with 3 radiobutton options to choose from and all this inside a ScrollView Linear Layout. I don't understand what the problem is. I'm new to android coding. Is it something to do with the ScrollView?? ThankYou in Advance.
<?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="wrap_content"
tools:context="com.example.android.generalquiz.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16sp"
android:fontFamily="casual"
android:text="#string/quiz"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="#string/first"
android:textSize="18sp" />
<RadioButton
android:id="#+id/ans1"
style="#style/margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/largest" />
<RadioButton
style="#style/margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/longest" />
<RadioButton
style="#style/margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/none" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="#string/second"
android:textSize="18sp" />
<RadioButton
style="#style/margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/seconda" />
<RadioButton
style="#style/margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/secondb" />
<RadioButton
android:id="#+id/ans2"
style="#style/margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/secondc" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="#string/third"
android:textSize="18sp" />
<RadioButton
style="#style/margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/thirda" />
<RadioButton
style="#style/margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/thirdb" />
<RadioButton
android:id="#+id/ans3"
style="#style/margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/thirdc" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="#string/fourth"
android:textSize="18sp" />
<RadioButton
style="#style/margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/fourtha" />
<RadioButton
android:id="#+id/ans4"
style="#style/margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/fourthb" />
<RadioButton
style="#style/margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/fourthc" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="#string/fifth"
android:textSize="18sp" />
<RadioButton
android:id="#+id/ans5"
style="#style/margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/fiftha" />
<RadioButton
style="#style/margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/fifthb" />
<RadioButton
style="#style/margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/fifthc" />
</LinearLayout>
</ScrollView>
This is how it looks

Related

Android layout not behaving as expected

I'm using Android Studio to try and design a view with a GridLayout at the, a GridView in the middle and a Button at the bottom.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="#dimen/margin"
android:layout_weight=".1"
android:orientation="vertical">
<RadioGroup
android:id="#+id/deliveryType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent">
<RadioButton
android:id="#+id/radWaitingOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/waiting" />
<RadioButton
android:id="#+id/radCollectionOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/collection" />
<RadioButton
android:id="#+id/radDeliveryOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/delivery" />
</RadioGroup>
<GridLayout
android:id="#+id/customerDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin">
<TextView
style="#style/caption"
android:layout_column="0"
android:layout_columnWeight=".1"
android:text="#string/name" />
<TextView
android:id="#+id/customerName"
style="#style/text"
android:layout_column="1"
android:layout_columnWeight=".5"
android:text="#string/name" />
<TextView
style="#style/caption"
android:layout_row="1"
android:layout_column="0"
android:layout_columnWeight=".1"
android:text="#string/address" />
<TextView
android:id="#+id/customerAddress"
style="#style/text"
android:layout_row="1"
android:layout_column="1"
android:layout_columnWeight=".5"
android:lines="4"
android:maxLines="4"
android:text="#string/address" />
<TextView
style="#style/caption"
android:layout_row="2"
android:layout_column="0"
android:layout_columnWeight=".1"
android:text="#string/phone" />
<TextView
android:id="#+id/customerPhone"
style="#style/text"
android:layout_row="2"
android:layout_column="1"
android:layout_columnWeight=".5"
android:text="#string/phone" />
</GridLayout>
<RadioGroup
android:id="#+id/deliveryCost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="#id/customerDetails">
<RadioButton
android:id="#+id/radLocalOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_2_00" />
<RadioButton
android:id="#+id/radNearOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_2_50" />
<RadioButton
android:id="#+id/radFarOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_3_00" />
</RadioGroup>
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="#dimen/margin"
android:layout_weight=".1"
android:orientation="vertical">
<GridLayout
android:id="#+id/filter"
android:layout_width="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_height="wrap_content">
<TextView
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_margin="#dimen/margin"
android:text="#string/filter" />
<EditText
android:id="#+id/txtFilter"
style="#style/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_margin="#dimen/margin"
android:hint="#string/filter_customers" />
</GridLayout>
<GridView
style="#style/margin"
android:id="#+id/customers"
app:layout_constraintTop_toBottomOf="#id/filter"
app:layout_constraintBottom_toTopOf="#+id/addButton"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_width="wrap_content"
android:layout_height="0dp">
</GridView>
<Button
style="#style/margin"
android:id="#+id/addButton"
android:layout_width="wrap_content"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_height="wrap_content"
android:text="Add"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
In the Android Studio designer it appears as I would expect:
but when it shows in the Android emulator, the Gridview appears to be expanded over the bottom of the screen and the button is not showing.
Can any give me pointers to what I have done wrong. Bare in mind this is my first attempt and a Kotlin program, coming from a dotnet background. Layout is so much easier in XAML :)
If you want the LinearLayout, ConstraintLayout and the button to stack up on top of each other, this should do it. It may need a bit of change on your end.
Replace your XML code with this and check:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:baselineAligned="false">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="#dimen/margin"
android:layout_weight=".1"
android:orientation="vertical">
<RadioGroup
android:id="#+id/deliveryType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent">
<RadioButton
android:id="#+id/radWaitingOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/waiting" />
<RadioButton
android:id="#+id/radCollectionOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/collection" />
<RadioButton
android:id="#+id/radDeliveryOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/delivery" />
</RadioGroup>
<GridLayout
android:id="#+id/customerDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin">
<TextView
style="#style/caption"
android:layout_column="0"
android:layout_columnWeight=".1"
android:text="#string/name" />
<TextView
android:id="#+id/customerName"
style="#style/text"
android:layout_column="1"
android:layout_columnWeight=".5"
android:text="#string/name" />
<TextView
style="#style/caption"
android:layout_row="1"
android:layout_column="0"
android:layout_columnWeight=".1"
android:text="#string/address" />
<TextView
android:id="#+id/customerAddress"
style="#style/text"
android:layout_row="1"
android:layout_column="1"
android:layout_columnWeight=".5"
android:lines="4"
android:maxLines="4"
android:text="#string/address" />
<TextView
style="#style/caption"
android:layout_row="2"
android:layout_column="0"
android:layout_columnWeight=".1"
android:text="#string/phone" />
<TextView
android:id="#+id/customerPhone"
style="#style/text"
android:layout_row="2"
android:layout_column="1"
android:layout_columnWeight=".5"
android:text="#string/phone" />
</GridLayout>
<RadioGroup
android:id="#+id/deliveryCost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="#id/customerDetails">
<RadioButton
android:id="#+id/radLocalOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_2_00" />
<RadioButton
android:id="#+id/radNearOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_2_50" />
<RadioButton
android:id="#+id/radFarOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_3_00" />
</RadioGroup>
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="#dimen/margin"
android:layout_weight=".1"
android:orientation="vertical">
<GridLayout
android:id="#+id/filter"
android:layout_width="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_height="wrap_content">
<TextView
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_margin="#dimen/margin"
android:text="#string/filter" />
<EditText
android:id="#+id/txtFilter"
style="#style/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_margin="#dimen/margin"
android:hint="#string/filter_customers" />
</GridLayout>
<GridView
style="#style/margin"
android:id="#+id/customers"
app:layout_constraintTop_toBottomOf="#id/filter"
app:layout_constraintBottom_toTopOf="#+id/addButton"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_width="wrap_content"
android:layout_height="0dp">
</GridView>
</androidx.constraintlayout.widget.ConstraintLayout>
<Button
style="#style/margin"
android:id="#+id/addButton"
android:layout_width="wrap_content"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_height="wrap_content"
android:text="Add"/>
</LinearLayout>

how to allow only one radiobtton to be executed in a radiogroup inside a linear layout?

I am trying to place a radio group with 3 radio buttons inside a linear layout. My aim is to choose only one RadioButton inside the RadioGroup but, it is giving me an error that there are multiple root tags. Can someone figure out how to solve this?
file.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ok"
android:id="#+id/textemail"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioButton
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
<RadioButton
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two"
/>
<RadioButton
android:id="#+id/three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three" />
</RadioGroup>
<TextView
android:id="#+id/textView1"
android:layout_below="#+id/textemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To:"
/>
<TextView
android:id="#+id/TextTo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="khushi"/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comment:"
/>
<TextView
android:id="#+id/TextS3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="your comment"
/>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="email us "
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:inputType="textMultiLine"
android:lines="10" />
<Button
android:id="#+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Send"
android:textStyle="italic"/>
</LinearLayout>
You immediately close your radiogroup:
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"/>
This should be:
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"> // Note that there is no forward slash at the end
And you are not closing the RadioGroup:
</RadioButton> <-- This should be </RadioGroup>
Your RadioButton (views) should be children of the RadioGroup(view). By closing your RadioGroup using /> you declare the RadioButton(s) and the RadioGroup as children of the LinearLayout.
The Following should work.
<?xml version="1.0" encoding="utf-8"?>
<Linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello"
android:id="#+id/textview"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioButton
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
<RadioButton
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two"
/>
<RadioButton
android:id="#+id/three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three" />
</RadioButton>
</RadioGroup>
<TextView
android:id="#+id/textViewllol"
android:layout_below="#+id/textemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hi:"
/>
<TextView
android:id="#+id/Texme"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="comment:"
/>
<TextView
android:id="#+id/Text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="your comments"
/>
<TextView
android:id="#+id/textView45"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ok"
/>
<EditText
android:id="#+id/editTextMessage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:lines="10" />
<Button
android:id="#+id/button4785"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="send"
/>
</LinearLayout>
Change below -
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"/>
to
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioButton
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
<RadioButton
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two"
/>
<RadioButton
android:id="#+id/three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three" />
</RadioGroup>
One of your Text is not in correct format change it as below -
<TextView
android:id="#+id/textView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ok:"
/>
to
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ok:"
/>
One more error -
change below -
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
to
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">
You have one </Radiobutton> tag above </Radiogroup> that shouldn't be here. Just remove it to have :
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioButton
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
<RadioButton
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two"
/>
<RadioButton
android:id="#+id/three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three" />
</RadioGroup>

Landscape layout padding issue

My XML layout in portrait is correct, however on my landscape view, some content is hidden behind my action bar.
see example below
and here is my XML Layout:
<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="match_parent"
android:paddingTop="#dimen/activity_horizontal_margin">
<LinearLayout
android:layout_width="600dp"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical"
android:layout_gravity="center"
tools:context="com.example.gharrington.myapplication.NewOrderForm"
>
<TextView
android:text="Name:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/FieldLabelStyle" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/edtName"
android:singleLine="true"
android:layout_marginBottom="#dimen/activity_horizontal_margin"
android:hint="Enter Name..." />
<TextView
android:text="Meal:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/FieldLabelStyle" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spnMeal"
android:entries="#array/meals"
android:layout_marginBottom="#dimen/activity_horizontal_margin" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/radioGroupMeal"
android:layout_marginBottom="#dimen/activity_horizontal_margin">
<RadioButton
android:layout_width="#dimen/radio_button_width"
android:layout_height="wrap_content"
android:text="Sandwich"
android:checked="true"
android:id="#+id/sandwich"
/>
<RadioButton
android:layout_width="#dimen/radio_button_width"
android:layout_height="wrap_content"
android:text="Meal"
android:orientation="horizontal"
android:layout_marginLeft="#dimen/activity_vertical_margin"
android:id="#+id/meal"
/>
</RadioGroup>
<TextView
android:text="Drink:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/FieldLabelStyle" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spnDrinks"
android:entries="#array/drinks"
android:layout_marginBottom="#dimen/activity_horizontal_margin"
/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/radioGroupDrink"
android:layout_marginBottom="#dimen/activity_horizontal_margin"
>
<RadioButton
android:layout_width="#dimen/radio_button_width"
android:layout_height="wrap_content"
android:text="Small"
android:checked="true"
android:id="#+id/small"
/>
<RadioButton
android:layout_width="#dimen/radio_button_width"
android:layout_height="wrap_content"
android:text="Regular"
android:layout_marginLeft="#dimen/activity_vertical_margin"
android:id="#+id/medium"
/>
<RadioButton
android:layout_width="#dimen/radio_button_width"
android:layout_height="wrap_content"
android:text="Large"
android:layout_marginLeft="#dimen/activity_vertical_margin"
android:id="#+id/large"
/>
</RadioGroup>
<TextView
android:text="Notes:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/FieldLabelStyle" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/notes"
android:hint="Notes"
android:layout_marginBottom="40dp" />
<TextView
android:text="Paid:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/FieldLabelStyle" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/paidcheckBox" />
<TextView
android:text="Total:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/FieldLabelStyle"
android:layout_gravity="right"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/total"
android:text="£0.00"
android:layout_gravity="right"
style="?android:textAppearanceLarge"
android:layout_marginBottom="#dimen/activity_horizontal_margin" />
<Button
android:text="Save"
android:id="#+id/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right" />
</LinearLayout>
</ScrollView>
Im pretty sure I should not have to account for the padding at the top.
try this
android:layout_gravity="center_horizontal"
for ur linear layout
In your LinearLayout Remove
android:layout_gravity="center"
and try it

Android xml layout about CheckBox and RadioButton

There have two RadioButton, Twelve Checkbox and one send button,each button has a custom selector.
RadioButton and Checkbox out of range, can not let all RadioButton and Checkbox in the android xml layout.
I used ScrollView, but it have some error about "Exception raised during rendering: ScrollView can host only one direct child".
I don't know how can RadioButton and Checkbox in there range.
How to change RadioButton and CheckBox in to the RadioButton in there range?
thanks.
<?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" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="#+id/etIdUserName2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10sp" />
<TextView
android:id="#+id/etIdUseracc2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10sp" />
<TextView
android:id="#+id/etIdPassre2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="使用者性別"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<RadioButton
android:id="#+id/boy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男" />
<RadioButton
android:id="#+id/girl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="使用者年齡"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<CheckBox
android:id="#+id/under"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="18以下"
android:textSize="15sp" />
<CheckBox
android:id="#+id/between2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="23~27"
android:textSize="15sp" />
<CheckBox
android:id="#+id/between1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="18~23"
android:textSize="15sp" />
<CheckBox
android:id="#+id/between3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="28~32"
android:textSize="15sp" />
<CheckBox
android:id="#+id/up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="32以上"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="使用者興趣"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<CheckBox
android:id="#+id/girluse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="女裝與服飾配件、女包精品與女鞋"
android:textSize="15sp" />
<CheckBox
android:id="#+id/makeup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="美容保養與彩妝"
android:textSize="15sp" />
<CheckBox
android:id="#+id/boyuse"
android:layout_width="152dp"
android:layout_height="wrap_content"
android:text="男性精品與服飾"
android:textSize="15sp" />
<CheckBox
android:id="#+id/electronicproduct"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="電腦、平板與周邊"
android:textSize="15sp" />
<CheckBox
android:id="#+id/cellphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="手機、配件與通"
android:textSize="15sp" />
<CheckBox
android:id="#+id/food"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="美食與地方特產"
android:textSize="15sp" />
<CheckBox
android:id="#+id/Stationery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="文具與事務用"
android:textSize="15sp" />
<Button
android:id="#+id/setbutton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="送出"
android:textSize="15sp" />
</ScrollView>
</LinearLayout>
"ScrollView can host only one direct child".
So simply wrap everything in a LinearLayout.
<?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" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:id="#+id/etIdUserName2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10sp" />
<TextView
android:id="#+id/etIdUseracc2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10sp" />
<TextView
android:id="#+id/etIdPassre2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="使用者性別"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<RadioButton
android:id="#+id/boy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男" />
<RadioButton
android:id="#+id/girl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="使用者年齡"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<CheckBox
android:id="#+id/under"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="18以下"
android:textSize="15sp" />
<CheckBox
android:id="#+id/between2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="23~27"
android:textSize="15sp" />
<CheckBox
android:id="#+id/between1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="18~23"
android:textSize="15sp" />
<CheckBox
android:id="#+id/between3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="28~32"
android:textSize="15sp" />
<CheckBox
android:id="#+id/up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="32以上"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="使用者興趣"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<CheckBox
android:id="#+id/girluse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="女裝與服飾配件、女包精品與女鞋"
android:textSize="15sp" />
<CheckBox
android:id="#+id/makeup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="美容保養與彩妝"
android:textSize="15sp" />
<CheckBox
android:id="#+id/boyuse"
android:layout_width="152dp"
android:layout_height="wrap_content"
android:text="男性精品與服飾"
android:textSize="15sp" />
<CheckBox
android:id="#+id/electronicproduct"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="電腦、平板與周邊"
android:textSize="15sp" />
<CheckBox
android:id="#+id/cellphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="手機、配件與通"
android:textSize="15sp" />
<CheckBox
android:id="#+id/food"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="美食與地方特產"
android:textSize="15sp" />
<CheckBox
android:id="#+id/Stationery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="文具與事務用"
android:textSize="15sp" />
<Button
android:id="#+id/setbutton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="送出"
android:textSize="15sp" />
</LinearLayout>
</ScrollView>
As per the Logcat says Exception raised during rendering: ScrollView can host only one direct child. One can have only one direct child view to ScrollView. As you have so many check boxes and RadioButton inside ScrollView it throws an error.
You just need to add all your Checkbox and RadioButton inside View with ParentView as ScrollView which can handle all your RadioButton and Checkboxes. In here I've added Linearlayout as ParentView for all your Checkboxes and RadioButton.
Explaination:
ScrollView // ParentView
LinearLayout // DirectChild of ScrollView
RadioButton & Checkboxes // Direct child of LinearLayout
Layout:
<?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" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="#+id/etIdUserName2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10sp" />
<TextView
android:id="#+id/etIdUseracc2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10sp" />
<TextView
android:id="#+id/etIdPassre2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="使用者性別"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<RadioButton
android:id="#+id/boy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男" />
<RadioButton
android:id="#+id/girl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="使用者年齡"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<CheckBox
android:id="#+id/under"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="18以下"
android:textSize="15sp" />
<CheckBox
android:id="#+id/between2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="23~27"
android:textSize="15sp" />
<CheckBox
android:id="#+id/between1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="18~23"
android:textSize="15sp" />
<CheckBox
android:id="#+id/between3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="28~32"
android:textSize="15sp" />
<CheckBox
android:id="#+id/up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="32以上"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="使用者興趣"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<CheckBox
android:id="#+id/girluse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="女裝與服飾配件、女包精品與女鞋"
android:textSize="15sp" />
<CheckBox
android:id="#+id/makeup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="美容保養與彩妝"
android:textSize="15sp" />
<CheckBox
android:id="#+id/boyuse"
android:layout_width="152dp"
android:layout_height="wrap_content"
android:text="男性精品與服飾"
android:textSize="15sp" />
<CheckBox
android:id="#+id/electronicproduct"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="電腦、平板與周邊"
android:textSize="15sp" />
<CheckBox
android:id="#+id/cellphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="手機、配件與通"
android:textSize="15sp" />
<CheckBox
android:id="#+id/food"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="美食與地方特產"
android:textSize="15sp" />
<CheckBox
android:id="#+id/Stationery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="文具與事務用"
android:textSize="15sp" />
<Button
android:id="#+id/setbutton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="送出"
android:textSize="15sp" />
</LinearLayout>
</ScrollView>
</LinearLayout>

ViewFliper in layout

i am doing one application in android but i have one problem in layout file
i am doing by viewFliper
here is 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" >
<TextView
android:id="#+id/Quesiontext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="44dp"
android:text="#string/Question"
android:textSize="18sp" />
<RadioGroup
android:id="#+id/radioGroupOptions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/Quesiontext"
android:layout_marginTop="30dp" >
<RadioButton
android:id="#+id/optionOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="#string/option1" />
<RadioButton
android:id="#+id/optionTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/option2" />
<RadioButton
android:id="#+id/optionthree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/option3" />
<RadioButton
android:id="#+id/optionFour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/option4" />
</RadioGroup>
<TextView
android:id="#+id/corrertView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/radioGroupOptions"
android:layout_marginRight="48dp"
android:text="#string/correct" />
<Button
android:id="#+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/corrertView"
android:layout_below="#+id/corrertView"
android:layout_marginTop="42dp"
android:text="#string/Next"
android:textSize="16sp" />
<Button
android:id="#+id/Btnpervious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/btnNext"
android:layout_alignBottom="#+id/btnNext"
android:layout_alignParentLeft="true"
android:text="#string/Pervious"
android:textSize="16sp" />
<RelativeLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ViewFlipper
android:id="#+id/ViewFlipper01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/Quesiontext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="44dp"
android:text="#string/Question"
android:textSize="18sp" />
<RadioGroup
android:id="#+id/radioGroupOptions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/Quesiontext"
android:layout_marginTop="30dp" >
<RadioButton
android:id="#+id/optionOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="#string/option1" />
<RadioButton
android:id="#+id/optionTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/option2" />
<RadioButton
android:id="#+id/optionthree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/option3" />
<RadioButton
android:id="#+id/optionFour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/option4" />
</RadioGroup>
<TextView
android:id="#+id/corrertView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/radioGroupOptions"
android:layout_marginRight="48dp"
android:text="#string/correct" />
</ViewFlipper>
</RelativeLayout>
</RelativeLayout>
i didnt get it that how i put another button into ViewFliper ..its confusion and generating error...
You haven't closed your ViewFlipper with </ViewFlipper>
Could this be what you are looking for,
android:id="#+id/layout"
You missed a "+" symbol while creating a id.

Categories

Resources